Skip to content

Commit

Permalink
feat: Add cleanup effect for unmounting (#64)
Browse files Browse the repository at this point in the history
* feat: Add cleanup effect for unmounting

This commit adds a useEffect cleanup function to the OverlayProvider component that dispatches a ‘REMOVE_ALL’ action upon unmounting.
This ensures that overlays are properly cleaned up during testing scenarios, preventing state leakage and side effects from persistent overlays.

* Create brown-boxes-wink.md
  • Loading branch information
jungpaeng authored Jul 17, 2024
1 parent 7d8b642 commit 01eaa3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .changeset/brown-boxes-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"overlay-kit": patch
---

feat: Add cleanup effect for unmounting

This commit introduces a useEffect cleanup function in the OverlayProvider component that dispatches a 'REMOVE_ALL' action when the component unmounts.
This change ensures that all overlays are properly cleaned up during testing scenarios, preventing state leakage and side effects from persistent overlays.

**Related Issue:** Fixes #63
6 changes: 6 additions & 0 deletions packages/src/context/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { overlay } from '../event';
export function OverlayProvider({ children }: PropsWithChildren) {
const overlayState = useSyncOverlayStore();

useEffect(() => {
return () => {
dispatchOverlay({ type: 'REMOVE_ALL' });
};
}, []);

return (
<OverlayContextProvider value={overlayState}>
{children}
Expand Down

0 comments on commit 01eaa3c

Please sign in to comment.