This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Emit<T> = (value: T) => void; | |
| type Subscribe<T> = (emit: Emit<T>) => void | (() => void); | |
| export async function* toAsyncIterator<T>(subscribe: Subscribe<T>): AsyncGenerator<T> { | |
| const queue = new AsyncQueue<T>(); | |
| const cleanup = subscribe(v => queue.push(v)); | |
| try { | |
| while (true) { | |
| yield queue.next(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 () => { |