react-codemirror icon indicating copy to clipboard operation
react-codemirror copied to clipboard

useCodeMirror: Updates to the onChange prop are ignored

Open jaller94 opened this issue 3 years ago • 1 comments

I strongly recommend to revert 387a0c5b11991841cd40c880bc95cb389de87022 because it has introduced a bug.

It doesn't call the correct onChange, if props.onChange gets changed by the parent component.

But why?

onChange is never updated (current behaviour)

const handleChange = useCallback((value: string, vu: ViewUpdate) => onChange && onChange(value, vu), []);

The handler is updated when onChange updates (correct behaviour)

This has the same behaviour as just calling onCall directly – besides the check for it being falsy.

const handleChange = useCallback((value: string, vu: ViewUpdate) => onChange && onChange(value, vu), [onChange]);

jaller94 avatar Aug 24 '22 11:08 jaller94

@jaller94 thx!

jaywcjlove avatar Aug 25 '22 02:08 jaywcjlove