Skip to content

Commit

Permalink
Re-export useBeforeUnload from react-router-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Dec 12, 2022
1 parent 0f389ab commit 09e580a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
23 changes: 0 additions & 23 deletions packages/remix-react/components.tsx
Expand Up @@ -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 `<Link>` 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 {
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-react/index.tsx
Expand Up @@ -12,6 +12,7 @@ export type {
export {
Form,
Outlet,
useBeforeUnload,
useFormAction,
useHref,
useLocation,
Expand Down Expand Up @@ -48,7 +49,6 @@ export {
useLoaderData,
useMatches,
useActionData,
useBeforeUnload,
} from "./components";

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

0 comments on commit 09e580a

Please sign in to comment.