Download react-use/src/useDeepCompareEffect.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 840 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useDeepCompareEffect.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useDeepCompareEffect.ts
-
curl -L -o useDeepCompareEffect.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useDeepCompareEffect.ts
840 Bytes
| import { DependencyList, EffectCallback } from 'react'; | |
| import useCustomCompareEffect from './useCustomCompareEffect'; | |
| import isDeepEqual from './misc/isDeepEqual'; | |
| const isPrimitive = (val: any) => val !== Object(val); | |
| const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => { | |
| if (process.env.NODE_ENV !== 'production') { | |
| if (!(deps instanceof Array) || !deps.length) { | |
| console.warn( | |
| '`useDeepCompareEffect` should not be used with no dependencies. Use React.useEffect instead.' | |
| ); | |
| } | |
| if (deps.every(isPrimitive)) { | |
| console.warn( | |
| '`useDeepCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.' | |
| ); | |
| } | |
| } | |
| useCustomCompareEffect(effect, deps, isDeepEqual); | |
| }; | |
| export default useDeepCompareEffect; | |