/** * @return A custom error message (most browser will ignore it), or just a * boolean to signal whether we want to prompt the user * * We might instead return an array with the above as first element and two * callbacks, but the callback technique is too cumbersome and unreliable * probably: * 2) A callback on confirmed leaving * 3) A callback on cancel, user stays on page */ export type UseNavigateAwayHandler = (event: BeforeUnloadEvent) => string | boolean; /** * @resources * * About browser's specs see: * - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event * - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5 * - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome * * About react see: * - https://github.com/jacobbuck/react-beforeunload * - https://github.com/dioscarey/react-beforeunload-component * * About next.js see: * - https://github.com/vercel/next.js/issues/2476 * - https://github.com/vercel/next.js/issues/2694 * * For the callback technique see: * - https://stackoverflow.com/a/11835394/1938970 */ export declare let useNavigateAway: (handler: UseNavigateAwayHandler) => void; export default useNavigateAway;