1import { Beforeunload } from 'react-beforeunload';
2
3class Example extends React.Component {
4 state = { value: '' };
5
6 render() {
7 return (
8 <>
9 {value !== '' && (
10 <Beforeunload onBeforeunload={(event) => event.preventDefault()} />
11 )}
12 <input
13 onChange={(event) => this.setState({ value: event.target.value })}
14 value={this.state.value}
15 />
16 </>
17 );
18 }
19}