0.1.2 • Published 1 year ago

detecting-router-change v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Detecting-router-change

This project allow you to detect user leaving page (react-router-dom v6.0.2)

Installation

yarn add detecting-router-change

or

npm i detecting-router-change

Usage

import { useCallbackPrompt } from 'detecting-router-change';

const App = () => {
    const [showDialog, setShowDialog] = useState<boolean>(false);
 const [showPrompt, confirmNavigation, cancelNavigation] =
				useCallbackPrompt(showDialog);

    const toggleDarkMode = (checked: boolean) => {
       setDarkMode(checked);
    };

   return (
		<div className="App">
			<header className="App-header">
				<img src={logo} className="App-logo" alt="logo" />
				<input onChange={() => setShowDialog(true)}></input>
			</header>
		</div>
	);
};

Props

NameTypeDefault ValueDescription
showDialogbooleanfalseif value=true,useCallbackPrompt start
detecting
cancelNavigationfunctioncancel the change
confirmNavigationfunctionvalid the change
showPromptnumberfalsecheck routing change