Chartjs-Why function is not updating with `useCallback` in React and Chart.js

1👍

It looks like chartjs-plugin-dragdata registers events on inialization and doesn’t update them later. You’d need to use useRef to get the current value.

const { activeState } = useContext(CertainContext);

const ref = useRef('');
ref.current = activeState;

...

const options = {
  // other options
  plugins: {
      dragData: {
          onDragStart: () => {
            console.log(ref.current);
          },
      }
  }
}

Leave a comment