diff --git a/src/hooks/useEffectState.tsx b/src/hooks/useEffectState.tsx index 02833f2..7823cc0 100644 --- a/src/hooks/useEffectState.tsx +++ b/src/hooks/useEffectState.tsx @@ -47,12 +47,22 @@ export default function useEffectState( // Value const [stateValue, setStateValue] = React.useState(defaultValue); + const abortController = new AbortController(); + // Set State const setEffectVal = useEvent((nextValue: Updater) => { notifyEffectUpdate(() => { - setStateValue(nextValue); - }); + if (!abortController.signal.aborted) { + setStateValue(nextValue); + } + }, abortController.signal); }); + useEffect(() => { + return () => { + abortController.abort(); + }; + }, []); + return [stateValue, setEffectVal]; }