Skip to content

Commit 47ca3bb

Browse files
committed
Re-export useBeforeUnload from react-router-dom
1 parent 5659a46 commit 47ca3bb

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

packages/remix-react/components.tsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -863,29 +863,6 @@ function dedupe(array: any[]) {
863863
return [...new Set(array)];
864864
}
865865

866-
/**
867-
* Setup a callback to be fired on the window's `beforeunload` event. This is
868-
* useful for saving some data to `window.localStorage` just before the page
869-
* refreshes, which automatically happens on the next `<Link>` click when Remix
870-
* detects a new version of the app is available on the server.
871-
*
872-
* Note: The `callback` argument should be a function created with
873-
* `React.useCallback()`.
874-
*
875-
* @see https://remix.run/api/remix#usebeforeunload
876-
*/
877-
export function useBeforeUnload(
878-
callback: (event: BeforeUnloadEvent) => any
879-
): void {
880-
// TODO: Export from react-router-dom
881-
React.useEffect(() => {
882-
window.addEventListener("beforeunload", callback);
883-
return () => {
884-
window.removeEventListener("beforeunload", callback);
885-
};
886-
}, [callback]);
887-
}
888-
889866
// TODO: Can this be re-exported from RR?
890867
export interface RouteMatch {
891868
/**

packages/remix-react/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export type {
1212
export {
1313
Form,
1414
Outlet,
15+
useBeforeUnload,
1516
useFormAction,
1617
useHref,
1718
useLocation,
@@ -48,7 +49,6 @@ export {
4849
useLoaderData,
4950
useMatches,
5051
useActionData,
51-
useBeforeUnload,
5252
} from "./components";
5353

5454
export type { FormMethod, FormEncType } from "./data";

0 commit comments

Comments
 (0)