diff --git a/packages/common/README/HOOKS.md b/packages/common/README/HOOKS.md index 8470f067c..b56aa0f69 100644 --- a/packages/common/README/HOOKS.md +++ b/packages/common/README/HOOKS.md @@ -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 diff --git a/packages/common/src/PreventExit/hooks.ts b/packages/common/src/PreventExit/hooks.ts index 61a160c94..2e556483a 100644 --- a/packages/common/src/PreventExit/hooks.ts +++ b/packages/common/src/PreventExit/hooks.ts @@ -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. @@ -20,5 +21,5 @@ export function usePreventExit( const { cleanup, setPreventExit, allowRedirect } = useMemo(createPreventExitListener, []); useEffect(() => setPreventExit(preventExit), [preventExit]); useEffect(() => cleanup, []); - return { allowRedirect }; + return useObjectMemo({ allowRedirect }); } diff --git a/packages/common/src/PreventExit/store.ts b/packages/common/src/PreventExit/store.ts index e8df91d15..9cadc1752 100644 --- a/packages/common/src/PreventExit/store.ts +++ b/packages/common/src/PreventExit/store.ts @@ -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) => {