Chartjs-Using Chart.js in functional React component, not allowing me to toggle data: "properties undefined"

1👍

Your problem is that positiveChart is not in the scope of your other functions because you declare it inside makeChart. In order to fix that you must have it in the react useState like this:

const [positiveChart, setPositiveChart] = React.useState(undefined);

and then inside makeChart you can use setPositiveChart in order to create it. Afterwards you will be able to access it correctly in your useEffect functions.

You can read more about it in the React docs about state hooks.

Leave a comment