From 09e580a06ac234ae523e139e1a221a58a45430cb Mon Sep 17 00:00:00 2001 From: Matt Brophy Date: Mon, 12 Dec 2022 18:18:37 -0500 Subject: [PATCH] Re-export useBeforeUnload from react-router-dom --- packages/remix-react/components.tsx | 23 ----------------------- packages/remix-react/index.tsx | 2 +- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/packages/remix-react/components.tsx b/packages/remix-react/components.tsx index 5dfb9e2b478..1701db57156 100644 --- a/packages/remix-react/components.tsx +++ b/packages/remix-react/components.tsx @@ -863,29 +863,6 @@ function dedupe(array: any[]) { return [...new Set(array)]; } -/** - * Setup a callback to be fired on the window's `beforeunload` event. This is - * useful for saving some data to `window.localStorage` just before the page - * refreshes, which automatically happens on the next `` click when Remix - * detects a new version of the app is available on the server. - * - * Note: The `callback` argument should be a function created with - * `React.useCallback()`. - * - * @see https://remix.run/api/remix#usebeforeunload - */ -export function useBeforeUnload( - callback: (event: BeforeUnloadEvent) => any -): void { - // TODO: Export from react-router-dom - React.useEffect(() => { - window.addEventListener("beforeunload", callback); - return () => { - window.removeEventListener("beforeunload", callback); - }; - }, [callback]); -} - // TODO: Can this be re-exported from RR? export interface RouteMatch { /** diff --git a/packages/remix-react/index.tsx b/packages/remix-react/index.tsx index 4edba6613aa..b3fda3a9ed7 100644 --- a/packages/remix-react/index.tsx +++ b/packages/remix-react/index.tsx @@ -12,6 +12,7 @@ export type { export { Form, Outlet, + useBeforeUnload, useFormAction, useHref, useLocation, @@ -48,7 +49,6 @@ export { useLoaderData, useMatches, useActionData, - useBeforeUnload, } from "./components"; export type { FormMethod, FormEncType } from "./data";