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

200
Visualizações
I am trying to print props in console but when i write console.log(props.details) it prints it twice in console

Once I render this functional component and open the console to check if props are present or not. The console shows me props containing array two times but the first time printed array is empty and the array that was printed the second time contains the data. I am really confused and unable to debug this error.

Below is the code:

const MainConents = (props) => {
        console.log(props.details);
    return ( 
        <>
            <div className="container" style={{marginTop : "20px"}}>
                <div className="row">
                    <div className="col-12">
                            // show single post in loop wise from database
                            // show pagination for posts
                    </div>
                </div>
            </div>
        </>
    );
}

export default MainConents;

The output in my browser is:

this is the link of image

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

0

props are passed from a parent component and I believe these details are fetched by invoking an api endpoint.

Therefore, during the initial rendering backend server didn't respond back with a response and as a result, it will show an empty array at the beginning (which is initial value of props.details). But when it sends the response, props.details are now updated and as a result child component MainConents will be re-rendered. Then, it will show the updated array in the console logs.

Therefore, initially you'll see an empty array and then the updated props.details.

If you only need to print the array when it's not empty. Then you can put a simple condition as follows. (But it's not necessary, because console logs are only used for debug purposes)

if(props.details.length > 0){
console.log(props.details);
}
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