Skip to content

Instantly share code, notes, and snippets.

@sibelius
sibelius / usePrompt.tsx
Last active October 27, 2022 19:05
Prompt user before leaving route or reload
import { useEffect, useRef } from 'react';
import { useHistory } from 'react-router-dom';
export const usePrompt = (when: boolean, message: string = 'Are you sure you want to quit without saving your changes?') => {
const history = useHistory();
const self = useRef(null);
const onWindowOrTabClose = event => {
if (!when) {
@kuanhsuh
kuanhsuh / webdev_online_resources.md
Created August 27, 2018 08:03 — forked from bradtraversy/webdev_online_resources.md
Online Resources For Web Developers (No Downloading)