|
Download react-use/docs/useShallowCompareEffect.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 601 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useShallowCompareEffect.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useShallowCompareEffect.md
-
curl -L -o useShallowCompareEffect.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useShallowCompareEffect.md
601 Bytes
| # `useShallowCompareEffect` | |
| A modified useEffect hook that is using shallow comparison on each of its dependencies instead of reference equality. | |
| ## Usage | |
| ```jsx | |
| import {useCounter, useShallowCompareEffect} from 'react-use'; | |
| const Demo = () => { | |
| const [count, {inc: inc}] = useCounter(0); | |
| const options = { step: 2 }; | |
| useShallowCompareEffect(() => { | |
| inc(options.step) | |
| }, [options]); | |
| return ( | |
| <div> | |
| <p>useShallowCompareEffect: {count}</p> | |
| </div> | |
| ); | |
| }; | |
| ``` | |
| ## Reference | |
| ```ts | |
| useShallowCompareEffect(effect: () => void | (() => void | undefined), deps: any[]); | |
| ``` | |