Skip to content

Instantly share code, notes, and snippets.

View denchiklut's full-sized avatar
🏳️‍🌈

Karl Aleksandrov denchiklut

🏳️‍🌈
View GitHub Profile
@denchiklut
denchiklut / promt.hook.ts
Last active May 11, 2023 09:52
usePromt
import { useEffect } from 'react'
import { unstable_useBlocker as useBlocker } from 'react-router-dom'
export function usePrompt(message: string, when = true) {
const blocker = useBlocker(when)
useEffect(() => {
if (when) window.onbeforeunload = () => message
return () => {