source: imaps-frontend/node_modules/react-use/esm/useShallowCompareEffect.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 962 bytes
RevLine 
[d565449]1import { equal as isShallowEqual } from 'fast-shallow-equal';
2import useCustomCompareEffect from './useCustomCompareEffect';
3var isPrimitive = function (val) { return val !== Object(val); };
4var shallowEqualDepsList = function (prevDeps, nextDeps) {
5 return prevDeps.every(function (dep, index) { return isShallowEqual(dep, nextDeps[index]); });
6};
7var useShallowCompareEffect = function (effect, deps) {
8 if (process.env.NODE_ENV !== 'production') {
9 if (!(deps instanceof Array) || !deps.length) {
10 console.warn('`useShallowCompareEffect` should not be used with no dependencies. Use React.useEffect instead.');
11 }
12 if (deps.every(isPrimitive)) {
13 console.warn('`useShallowCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.');
14 }
15 }
16 useCustomCompareEffect(effect, deps, shallowEqualDepsList);
17};
18export default useShallowCompareEffect;
Note: See TracBrowser for help on using the repository browser.