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

218
Visualizações
Map method is not rendering components in React.js

I have this as top component:

  const [allThreads, setAllThreads] = useState([{ post: "b" }]);
  
  return (
    <div className="App">
     
      <Main allThreads={allThreads} key={3} />
      
    </div>
  );
}
export default App;

This is my Main component:

import "../scss/App.scss";
import Thread from "./Thread";

function Main(props) {
  console.log("props received in Main" + JSON.stringify(props));
  return (
    <div className="main">
      <span>main</span>
      {props.allThreads.map((thread) => {
        console.log("appending posts in list");
        console.log(thread.post);
        <Thread post={thread.post} />;
      })}
    </div>
  );
}

export default Main;

And this is Thread component:

import "../scss/App.scss";
function Thread(props) {
  console.log("reached thread method");
  return <div className="thread">{props.post}</div>;
}
export default Thread;

But iteration is never reaching Thread component. And this [{ post: "b" }] that i used as initial state is not getting printed on screen. What could be the issue? That is currently the output coming:enter image description here

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

0

It is because you are not returning anything in your map. It is a common mistake. map always need to return something. Try with this :

import "../scss/App.scss";
import Thread from "./Thread";

function Main(props) {
  console.log("props received in Main" + JSON.stringify(props));
  return (
    <div className="main">
      <span>main</span>
      {props.allThreads.map((thread) => {
        console.log("appending posts in list");
        console.log(thread.post);
        return <Thread post={thread.post} />;
      })}
    </div>
  );
}

export default Main;
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