[Chartjs]-How to get the setState reassigned in react

1👍

Welcome to stackoverflow

  • The function should be moved into the useEffect.

https://reactjs.org/docs/hooks-effect.html#example-using-hooks-1

  • Not sure why chartData is on the dependency array, doesn’t it get an infinite loop? If you want the function to run only 1 time, you can change [chartData] to []

https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects

0👍

I ended up finding the problem. The state was being updated correctly. I had the data formatted wrong within the data set so it wouldn’t render anything on the page. I just had to remove the [] from around the background color line.

Leave a comment