1👍
✅
It seems like you’re setting the data in your constructor:
constructor(props){
super(props);
this.state = {
chartData : {...}
}
}
A constructor is only called once when an object is initialized. (In ReactJS, it is only called after the first render.)
You are calling setState()
, and the rest appears to be good, that I can tell. Why don’t you move this.state = {...}
from the constructor to render()
? Since render()
runs whenever the state is changed, your setState()
calls should work.
It may be inelegant, and there can certainly be improvements, but it will get you started in the right direction.
Source:stackexchange.com