diff --git a/src/Button/MeasureButton/MeasureButton.tsx b/src/Button/MeasureButton/MeasureButton.tsx index 6f19c3b65..436da652c 100644 --- a/src/Button/MeasureButton/MeasureButton.tsx +++ b/src/Button/MeasureButton/MeasureButton.tsx @@ -517,8 +517,12 @@ export const MeasureButton: FC = ({ const onMapClickKey = map?.on('click', onMapClick); return () => { - unByKey(onDrawStartKey); - unByKey(onDrawEndKey); + if (!_isNil(onDrawStartKey)) { + unByKey(onDrawStartKey); + } + if (!_isNil(onDrawEndKey)) { + unByKey(onDrawEndKey); + } if (onMapPointerMoveKey) { unByKey(onMapPointerMoveKey); }