score:1

Accepted answer

it doesn't work because there are no further state updates after you assign the ref to the canvas; that means no more re-renderings (calls to render method) so you never get to execute this.chart(). instead of calling that last method in render, add it to the setstate callback in fakeapicall:

this.setstate({
    data: [1,2,3],
    labels: ['a', 'b', 'c']
}, () => this.chart());

the callback will be executed once setstate is completed and the component is re-rendered. you can read more about state callbacks here.


Related Query

More Query from same tag