Chartjs-<Canvas is already in use. Chart with ID '18' must be destroyed before the canvas can be reused> in react

0👍

Check out this thread in react-chartjs-2′ issues. Specifically MartinP-C’s comment.

I was getting this error (again with React 18.0.1, in Strict Mode)
Removing Strict Mode stops the error (because Strict Mode double-invokes lifecycle functions when in dev mode? Hence re-use of canvas? https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects)

However! Strict Mode wasn’t the problem itself.
I had not registered a Chart.JS component and the error being thrown (‘"arc" is not a registered element’) must have caused React to double-invoke and try to re-use the canvas.

Fixing the registered element error also stopped "Canvas already in use" error.
(Registering components: https://react-chartjs-2.js.org/docs/migration-to-v4#tree-shaking)

Leave a comment