Download react-use/stories/useDebounce.story.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.08 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/useDebounce.story.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/stories/useDebounce.story.tsx
-
curl -L -o useDebounce.story.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/useDebounce.story.tsx
1.08 kB
| import { storiesOf } from '@storybook/react'; | |
| import * as React from 'react'; | |
| import { useDebounce } from '../src'; | |
| import ShowDocs from './util/ShowDocs'; | |
| const Demo = () => { | |
| const [state, setState] = React.useState('Typing stopped'); | |
| const [val, setVal] = React.useState(''); | |
| const [debouncedValue, setDebouncedValue] = React.useState(''); | |
| const [, cancel] = useDebounce( | |
| () => { | |
| setState('Typing stopped'); | |
| setDebouncedValue(val); | |
| }, | |
| 2000, | |
| [val] | |
| ); | |
| return ( | |
| <div> | |
| <input | |
| type="text" | |
| value={val} | |
| placeholder="Debounced input" | |
| onChange={({ currentTarget }) => { | |
| setState('Waiting for typing to stop...'); | |
| setVal(currentTarget.value); | |
| }} | |
| /> | |
| <div>{state}</div> | |
| <div> | |
| Debounced value: {debouncedValue} | |
| <button onClick={cancel}>Cancel debounce</button> | |
| </div> | |
| </div> | |
| ); | |
| }; | |
| storiesOf('Side effects/useDebounce', module) | |
| .add('Docs', () => <ShowDocs md={require('../docs/useDebounce.md')} />) | |
| .add('Demo', () => <Demo />); | |