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 <></>;
* Be the first to Make Comment