cancel the debounce in the cleanup function that actually handles the event setup and teardown, where it belongs
Signed-off-by: Morgan Bentell <mbentell@spotify.com>
This commit is contained in:
@@ -82,18 +82,15 @@ export const useShadowRootSelection = (waitMillis: number = 0) => {
|
||||
[shadowRoot, setSelection, waitMillis],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
// cancel debounce on unmount
|
||||
return () => handleSelectionChange.cancel();
|
||||
}, [handleSelectionChange]);
|
||||
|
||||
useEffect(() => {
|
||||
window.document.addEventListener('selectionchange', handleSelectionChange);
|
||||
return () =>
|
||||
return () => {
|
||||
handleSelectionChange.cancel();
|
||||
window.document.removeEventListener(
|
||||
'selectionchange',
|
||||
handleSelectionChange,
|
||||
);
|
||||
};
|
||||
}, [handleSelectionChange]);
|
||||
|
||||
return selection;
|
||||
|
||||
Reference in New Issue
Block a user