-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
The section on "Charts.js object" shows registering an inline plugin in componentWillMount(). This is not a good practice as written, since if the component is mounted and unmounted later, a new (duplicate) plugin will be registered every time. Also, componentWillMount can be triggered multiple times. Finally, this lifecycle method is deprecated in React 17.
As a note, I'm using typescript and it complains that react-chartjs-2 does not have an export "Chart", and indeed it doesn't in the index.d.ts file, though obviously the actual library code does (so this is just a typings issue). Rather than declare a custom module, I ended up importing Chart from chart.js itself, which works fine since Chart represents the global chart.js Chart object as far as I can tell.