Skip to content

Instantly share code, notes, and snippets.

View kanavi57's full-sized avatar
👏
Hii

Nam Nguyen kanavi57

👏
Hii
View GitHub Profile
@MarksCode
MarksCode / use-prompt.ts
Last active October 31, 2024 11:03
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);