mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
Improve useBeforeUnload story, #220
This commit is contained in:
parent
048030d855
commit
409db4f2d1
@ -1,14 +1,16 @@
|
||||
import {storiesOf} from '@storybook/react';
|
||||
import * as React from 'react';
|
||||
import {useBeforeUnload} from '..';
|
||||
import {useToggle, useBeforeUnload} from '..';
|
||||
import ShowDocs from './util/ShowDocs';
|
||||
|
||||
const Demo = () => {
|
||||
useBeforeUnload();
|
||||
const [dirty, toggleDirty] = useToggle(false);
|
||||
useBeforeUnload(dirty, 'You have unsaved changes, are you sure?');
|
||||
|
||||
return (
|
||||
<div>
|
||||
Try to reload or close tab
|
||||
{dirty && 'Try to reload or close tab'}
|
||||
<button onClick={() => toggleDirty()}>{dirty ? 'Disable' : 'Enable'}</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user