GithubHelp home page GithubHelp logo

Comments (7)

rua02me avatar rua02me commented on May 16, 2024 1

@mauvpark YOU ARE A HERO!!!!!!!!

from project_mern_memories.

mauvpark avatar mauvpark commented on May 16, 2024

part 3,4,5 updated.

from project_mern_memories.

fkhan698 avatar fkhan698 commented on May 16, 2024

@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>
  );
}

from project_mern_memories.

mauvpark avatar mauvpark commented on May 16, 2024

@fkhan698 Hello, getting posts from api has following work flow.

client

  1. Call getPosts(actions/posts) and dispatch it to redux using redux-thunk in Home.js
  2. getPosts(actions/posts) calls api request
  3. fetchPosts(api/index.js but you are api/posts check out your module path) calls server "Get posts from server."

server

  1. router(server/routes/posts.js) calls getPosts from controllers.
  2. getPosts(server/controllers/posts.js) calls posts from mongo DB, then return response. (Success: posts, Fail: error)

back to client

  1. asynchronous getPosts(actions/posts.js) gets response from server(what you are looking for "data") and send it to redux storage.
  2. redux updates posts, send updated posts to Posts component(components/Posts/Posts.js).
  3. Posts Component updates posts and show those.

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!

from project_mern_memories.

mozyao avatar mozyao commented on May 16, 2024

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:)

from project_mern_memories.

mauvpark avatar mauvpark commented on May 16, 2024

@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.

from project_mern_memories.

bangkitdc avatar bangkitdc commented on May 16, 2024

@mozyao can you elaborate? I still got 404 error :((

from project_mern_memories.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.