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

117
Views
In First render it shows "undefined" and in second render it shows "data" in React.js

My problem is that when I send Array of data as prop and console.log it in another component , it first shows "undefined" and then it shows the data. I get data from API and then send it as prop to another component. I already removed React.strictMode from index.js file but it still keeps happening.

for example :

const menu = [
{name : "firstFood"},{name:"Second Food"}
]

<MenuTable menu ={menu} />

and in other component I console.log it.

const MenuTable = (props)=>{
console.log(props.menu)
}

In first render it shows undefined then it shows data

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you wrote:

 const [menu, setMenu] = useState()

Then you call the api and setMenu(response) with the data response. Therefore, menu, at first, is undefined. You should try useState([]), then the first render of menu is [].

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!