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

199
Views
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 answers
Answer question

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 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!