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
|
Line | |
---|
1 | import { equal as isShallowEqual } from 'fast-shallow-equal';
|
---|
2 | import useCustomCompareEffect from './useCustomCompareEffect';
|
---|
3 | var isPrimitive = function (val) { return val !== Object(val); };
|
---|
4 | var shallowEqualDepsList = function (prevDeps, nextDeps) {
|
---|
5 | return prevDeps.every(function (dep, index) { return isShallowEqual(dep, nextDeps[index]); });
|
---|
6 | };
|
---|
7 | var 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 | };
|
---|
18 | export default useShallowCompareEffect;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.