Skip to content

Improve "Chart.js object" section in usage instructions #336

@domehead100

Description

@domehead100

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions