Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
React component not rendering despite event firing

I'm making a blog with react, next.js, and json-server. I have come as far as dynamically loading blog posts and other UI, but now when I'm trying to load the comments dynamically as well, it's not working.

The component in question is this one.

const Comments = ({ id }) => {
  const [com, setCom] = useState([]);

  useEffect(() => {
    const getComments = async () => {
      const comment = await fetchPost(id);

      if (comment["comments"].length == 0) return;

      const comments = [...comment["comments"]];

      setCom([...comment["comments"]]);
    };

    getComments();
  }, []);

  return (
    <div>
      {com.map((p) => {
        console.log(p.comment);
        <Comment key={p.id} comment={p.comment} />;
      })}
    </div>
  );
};

I know that the component is getting called and have the information as I'm logging it to console inside map. What I can't get my head around is why it is not rendering as it is a near carbon copy of how I render the blog-posts.

Aside from the above, I have tried the following:

  • checked syntax
  • Running <Comment/> with and without a key
  • putting in strings directly inside the component com.map, instead of p.comment == does not render
  • lifting state and useEffect up to <Post/>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your function is not returning anything so React has nothing to render

{com.map((p) => (
  <Comment key={p.id} comment={p.comment} />;
))}

The following code returns nothing

() => { const value = 1; }

The following code returns 1

() => { const value = 1; return value;}

The following code returns 1

() => 1
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!