Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
My jsx is not populating when I used useEffect and useState

my file code where I am populating the code

import React, { useEffect, useState } from "react";
import blogStyle from "../styles/Blog.module.css";
import Link from "next/link";

function blog() {
  const [blogs, setBlogs] = useState([]);
  useEffect(() => {
    fetch("http://localhost:3000/api/allBlogs")
      .then((parsingData) => {
        return parsingData.json();
      })
      .then((data) => {
        setBlogs(data);
        console.log(data);
      });
  }, []);

  return (
    <>
      <div className={blogStyle.blog}>
        {blogs.map((blogItem) => {
          <div className={blogStyle.blogItemTemplate} key={blogItem.title}>
            <Link href={`/blogPost/how-to-learn-js`}>
              <h2 className={blogStyle.blogItemHeading}>{blogItem.title}</h2>
            </Link>
            <p className={blogStyle.blogItemPara}>{blogItem.content}</p>
            <div className={blogStyle.blogItemPara}>{blogItem.writer}</div>
          </div>;
        })}
      </div>
    </>
  );
}

what I am getting in my localhost image here

Everything works fine no error in the console and I got the fetched data. I stored the fetched data in blogs using useState which is successful but when i use the blogs in jsx to populate data nothing shows up . Using map function I got the title and description when I console logged it but not showing in the localhost

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I'm quite certain that you have some extra braces, try this instead:

{blogs.map((blogItem) => ( // <-- see here
    <div className={blogStyle.blogItemTemplate} key={blogItem.title}>
        <Link href={`/blogPost/how-to-learn-js`}>
            <h2 className={blogStyle.blogItemHeading}>{blogItem.title}</h2>
        </Link>
        <p className={blogStyle.blogItemPara} >{blogItem.content}</p>
        <div className={blogStyle.blogItemPara}>{blogItem.writer}</div>
    </div>
))} // <-- and here
about 4 years ago · Juan Pablo Isaza Relatório

0

write the jsx code in return statement like blogs.map((blogItem) => {return (...your jsx code)}), otherwise try this blogs.map((blogItem) => (...your jsx code.)).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda