Skip to content

Instantly share code, notes, and snippets.

View BustamanteMelkia's full-sized avatar
:octocat:
Working from home

Melquiades Bustamante BustamanteMelkia

:octocat:
Working from home
  • BUAP
  • Puebla, México.
View GitHub Profile
@MarksCode
MarksCode / use-prompt.ts
Last active May 28, 2024 12:55
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);