Download react-use/stories/useDeepCompareEffect.story.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 854 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/useDeepCompareEffect.story.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/stories/useDeepCompareEffect.story.tsx
-
curl -L -o useDeepCompareEffect.story.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/stories/useDeepCompareEffect.story.tsx
854 Bytes
| import { storiesOf } from '@storybook/react'; | |
| import * as React from 'react'; | |
| import { useCounter, useDeepCompareEffect } from '../src'; | |
| import ShowDocs from './util/ShowDocs'; | |
| const Demo = () => { | |
| const [countNormal, { inc: incNormal }] = useCounter(0); | |
| const [countDeep, { inc: incDeep }] = useCounter(0); | |
| const options = { max: 500 }; | |
| React.useEffect(() => { | |
| if (countNormal < options.max) { | |
| incNormal(); | |
| } | |
| }, [options]); | |
| useDeepCompareEffect(() => { | |
| if (countNormal < options.max) { | |
| incDeep(); | |
| } | |
| }, [options]); | |
| return ( | |
| <div> | |
| <p>useEffect: {countNormal}</p> | |
| <p>useDeepCompareEffect: {countDeep}</p> | |
| </div> | |
| ); | |
| }; | |
| storiesOf('Lifecycle/useDeepCompareEffect', module) | |
| .add('Docs', () => <ShowDocs md={require('../docs/useDeepCompareEffect.md')} />) | |
| .add('Demo', () => <Demo />); | |