|
Download react-use/docs/useCustomCompareEffect.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 776 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useCustomCompareEffect.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useCustomCompareEffect.md
-
curl -L -o useCustomCompareEffect.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/docs/useCustomCompareEffect.md
776 Bytes
useCustomCompareEffect
A modified useEffect hook that accepts a comparator which is used for comparison on dependencies instead of reference equality.
Usage
import {useCounter, useCustomCompareEffect} from 'react-use';
import isEqual from 'lodash/isEqual';
const Demo = () => {
const [count, {inc: inc}] = useCounter(0);
const options = { step: 2 };
useCustomCompareEffect(() => {
inc(options.step)
}, [options], (prevDeps, nextDeps) => isEqual(prevDeps, nextDeps));
return (
<div>
<p>useCustomCompareEffect with deep comparison: {count}</p>
</div>
);
};
Reference
useCustomCompareEffect(effect: () => void | (() => void | undefined), deps: any[], depsEqual: (prevDeps: any[], nextDeps: any[]) => boolean);