react-chartjs-2 not updating graph when state updates
Check this link. You can see that he binds the function to the component.
https://codepen.io/gaearon/pen/xEmzGg?editors=0010
// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
The potential issue I see is that you try to update nested property while you mutate it. So if Doughnut
is passing parts of data
to other components they will not be notified that props have changed. So it is necessary to do deep clone:
increment() {
const datasetsCopy = this.state.data.datasets.slice(0);
const dataCopy = datasetsCopy[0].data.slice(0);
dataCopy[0] = dataCopy[0] + 10;
datasetsCopy[0].data = dataCopy;
this.setState({
data: Object.assign({}, this.state.data, {
datasets: datasetsCopy
})
});
}
You may also need to bind the function like @Janick Fisher suggests.