From e95f7c88eb179a2691c3e79f282103ecb2f863f0 Mon Sep 17 00:00:00 2001 From: arunachalam Date: Wed, 17 Jul 2024 13:45:42 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20some=20types=20and=20extras?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/common/README/HOOKS.md | 2 -- packages/common/src/PreventExit/hooks.ts | 3 ++- packages/common/src/PreventExit/store.ts | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) 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) => {