Open mauvpark opened 3 years ago
part 3,4,5 updated.
@Mauv-hub I'm having issues with my posts showing up. In my Posts.js
page. I am able to console.log the data put nothing is showing up on my screen. I have the following code
import { useState, useEffect } from "react";
import { fetchPosts } from "../../api/posts";
import { Grid } from "@material-ui/core";
import { useSelector } from "react-redux";
import Post from "./Post/post.js";
import { useStyles } from "./Post/styles";
import styles from "../Posts/Posts.module.css";
export default function Posts() {
const [postsData, setPostsData] = useState([]);
const posts = useSelector(state => state.posts);
const classes = useStyles();
useEffect(() => {
const getData = async () => {
const response = await fetchPosts();
const data = response.data;
console.log(data);
setPostsData(data);
};
getData();
}, []);
return (
<div className={styles.grid}>
{posts.map(post => (
<div>
<Post key={post._id} post={post} />
</div>
))}
</div>
);
}
@fkhan698 Hello, getting posts from api has following work flow.
You should check where is wrong if you don't get any response error( you should return something in server side using res.status ... something) it would probably occur in API side or would be your reference error. I suggest to use eslint for checking it.
Good luck!
I am using port 8080 of my server due to the error: the 5000 is already in use, I tried many ways, but I failed.
All stuff work for me except the warning: src/reducers/posts.js Line 3:1: Assign arrow function to a variable before exporting as module default
Until I stuck at the last section of Video 1: create a post. I keep getting the error: POST http://localhost:8080/posts 404 (Not Found)
I am a newbie not familiar with the full stack. Thanks in advance if anyone one can help:)
@mozyao Hello, you can kill port npx kill-port 5000
. Could you show me your code where exactly problem happens? If you got 404 error, you should check out your data flow. I suggest to use console.log for debugging for that. For example, you could check your req.body
before create post to the mongo DB. If req.body
has right value, then check your newPostMessage
comes from PostMessage
. You will find some error during giving arguments.
@mauvpark YOU ARE A HERO!!!!!!!!
@mozyao can you elaborate? I still got 404 error :((
Hello, guys. Appreciate this great videos to Js Mastery. I made my cloned project following his videos. And modified some issues. If you got stuck some error, check out my project and read file. This project is till part 2 yet, so be careful who wants to find debug solution over part 2.
https://github.com/Mauv-hub/JsMastery-MERN-project