alexa

Why is it not filling the useState whin i get the data in react js?

Why is it not filling the useState whin i get the data in react js?

You are not getting the data in console.log since setChartData does change the state, but the changed state is not still available on the next row.

You are getting the error since, at the very beginning, before the data is loaded in the object after the asynchronous call, the object is {}, so it is empty and does not have any key.

You should avoid to display the Bar component before data is loaded, so you can put a loading state or check any key you are expecting in the object, like

 if (chartData.data) {
  return <Bar />; // With the props you need
}
return <></>;

192 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry