main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | var react_1 = require("react");
|
---|
| 4 | var isPrimitive = function (val) { return val !== Object(val); };
|
---|
| 5 | var useCustomCompareEffect = function (effect, deps, depsEqual) {
|
---|
| 6 | if (process.env.NODE_ENV !== 'production') {
|
---|
| 7 | if (!(deps instanceof Array) || !deps.length) {
|
---|
| 8 | console.warn('`useCustomCompareEffect` should not be used with no dependencies. Use React.useEffect instead.');
|
---|
| 9 | }
|
---|
| 10 | if (deps.every(isPrimitive)) {
|
---|
| 11 | console.warn('`useCustomCompareEffect` should not be used with dependencies that are all primitive values. Use React.useEffect instead.');
|
---|
| 12 | }
|
---|
| 13 | if (typeof depsEqual !== 'function') {
|
---|
| 14 | console.warn('`useCustomCompareEffect` should be used with depsEqual callback for comparing deps list');
|
---|
| 15 | }
|
---|
| 16 | }
|
---|
| 17 | var ref = react_1.useRef(undefined);
|
---|
| 18 | if (!ref.current || !depsEqual(deps, ref.current)) {
|
---|
| 19 | ref.current = deps;
|
---|
| 20 | }
|
---|
| 21 | react_1.useEffect(effect, ref.current);
|
---|
| 22 | };
|
---|
| 23 | exports.default = useCustomCompareEffect;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.