cancel debounced function on unmount to avoid updating state on an umounted component

Signed-off-by: Morgan Bentell <mbentell@spotify.com>
This commit is contained in:
Morgan Bentell
2023-03-01 13:55:58 +01:00
parent 08048a5a8b
commit 7cf160e4bc
+2
View File
@@ -82,6 +82,8 @@ export const useShadowRootSelection = (waitMillis: number = 0) => {
[shadowRoot, setSelection, waitMillis],
);
useEffect(() => handleSelectionChange.cancel);
useEffect(() => {
window.document.addEventListener('selectionchange', handleSelectionChange);
return () =>