Skip to content

Instantly share code, notes, and snippets.

View yara-tle's full-sized avatar

Thomas Lein yara-tle

  • Dfind
  • Oslo
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);