Skip to content
Advertisement

Chart JS in React doesn’t fetch data

I’ve built a coronavirus table and whenever someone clicks on the name of the particular country modal pops up with active cases chart. I realized that it might be an issue with the Modal Component imported from Bootstrap(but not quite sure). When I set the animation to false chart doesn’t show data on every modal opening. When the animation props are not included data sometimes is not loaded. Closing and reopening a couple of times does a trick tho.

JavaScript

Advertisement

Answer

try moving everything into useEffect like this. do not mix state and “let” variables.

I’m not sure what these 2 functions do, but it’s not advisable to those variables inside the function.

JavaScript

try these.

JavaScript
Advertisement