Skip to content

Commit

Permalink
👌 some types and extras
Browse files Browse the repository at this point in the history
  • Loading branch information
arunachalam-monk committed Jul 17, 2024
1 parent b9537e8 commit e95f7c8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
2 changes: 0 additions & 2 deletions packages/common/README/HOOKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ function MyComponent() {

This hook is used to prevent the user from leaving the page by displaying a confirmation dialog when the user tries to
leave the page.
usePreventExit expects a boolean value generally a expression.
allowRedirect - usePreventExit can be used multiple places. This act as a temporary override to allow to navigate.

### useQueue
```tsx
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/PreventExit/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useMemo } from 'react';
import { PreventExitListenerResult, createPreventExitListener } from './store';
import { useObjectMemo } from '../hooks';

/**
* Custom hook that allows preventing the user from exiting the page or navigating away.
Expand All @@ -20,5 +21,5 @@ export function usePreventExit(
const { cleanup, setPreventExit, allowRedirect } = useMemo(createPreventExitListener, []);
useEffect(() => setPreventExit(preventExit), [preventExit]);
useEffect(() => cleanup, []);
return { allowRedirect };
return useObjectMemo({ allowRedirect });
}
2 changes: 1 addition & 1 deletion packages/common/src/PreventExit/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function arePreventExitRemaining() {
return false;
}

function publish(id: symbol, preventExit: boolean) {
function publish(id: symbol, preventExit: boolean): void {
allPreventExitState[id] = preventExit;
if (!arePreventExitRemaining())
window.onbeforeunload = (e) => {
Expand Down

0 comments on commit e95f7c8

Please sign in to comment.