1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.useLayoutUpdateEffect = exports.default = void 0;
|
9 | var React = _interopRequireWildcard(require("react"));
|
10 | var _canUseDom = _interopRequireDefault(require("../Dom/canUseDom"));
|
11 |
|
12 |
|
13 |
|
14 | var useInternalLayoutEffect = process.env.NODE_ENV !== 'test' && (0, _canUseDom.default)() ? React.useLayoutEffect : React.useEffect;
|
15 | var useLayoutEffect = function useLayoutEffect(callback, deps) {
|
16 | var firstMountRef = React.useRef(true);
|
17 | useInternalLayoutEffect(function () {
|
18 | return callback(firstMountRef.current);
|
19 | }, deps);
|
20 |
|
21 |
|
22 | useInternalLayoutEffect(function () {
|
23 | firstMountRef.current = false;
|
24 | return function () {
|
25 | firstMountRef.current = true;
|
26 | };
|
27 | }, []);
|
28 | };
|
29 | var useLayoutUpdateEffect = exports.useLayoutUpdateEffect = function useLayoutUpdateEffect(callback, deps) {
|
30 | useLayoutEffect(function (firstMount) {
|
31 | if (!firstMount) {
|
32 | return callback();
|
33 | }
|
34 | }, deps);
|
35 | };
|
36 | var _default = exports.default = useLayoutEffect; |
\ | No newline at end of file |