unsubscrive from onchange listener on unmount

This commit is contained in:
NikolaBorislavovHristov 2019-10-05 12:00:06 +03:00
parent 69e043fd57
commit ae4bfda554

View file

@ -21,12 +21,14 @@ const ColorPicker = ({ className, value, onChange }) => {
});
}, []);
React.useEffect(() => {
pickerRef.current.off('change');
pickerRef.current.on('change', (picker, color) => {
if (typeof onChange === 'function') {
onChange(AColorPicker.parseColor(color, COLOR_FORMAT));
}
});
return () => {
pickerRef.current.off('change');
};
}, [onChange]);
React.useEffect(() => {
if (AColorPicker.parseColor(pickerRef.current.color, COLOR_FORMAT) !== value) {