Skip to content

Instantly share code, notes, and snippets.

View serifcolakel's full-sized avatar

Serif COLAKEL serifcolakel

View GitHub Profile
@serifcolakel
serifcolakel / use-prompt.ts
Created June 6, 2023 20:40 — forked from MarksCode/use-prompt.ts
return `usePrompt` capabilities from react-router
/**
* Prompts a user when they exit the page
*/
import { useCallback, useContext, useEffect } from 'react';
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom';
function useConfirmExit(confirmExit: () => boolean, when = true) {
const { navigator } = useContext(NavigationContext);