UNPKG

refun

Version:

A collection of React Hook-enabled functions that compose harmoniously with each other. Similar to `recompose`, but:

38 lines (29 loc) 1.05 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.onLayout = void 0; var _react = require("react"); var _tsfn = require("tsfn"); var _utils = require("./utils"); var onLayout = function onLayout(onLayoutHandler, watchKeys) { return function (props) { var propsRef = (0, _react.useRef)(_tsfn.EMPTY_OBJECT); var useEffectFnRef = (0, _react.useRef)(_tsfn.NOOP); var watchValuesRef = (0, _react.useRef)(_tsfn.EMPTY_ARRAY); if (watchValuesRef.current === _tsfn.EMPTY_ARRAY || !(0, _utils.shallowEqualByKeys)(propsRef.current, props, watchKeys)) { watchValuesRef.current = watchKeys.map(function (k) { return props[k]; }); } propsRef.current = props; if (useEffectFnRef.current === _tsfn.NOOP) { useEffectFnRef.current = function () { return onLayoutHandler(propsRef.current); }; } (0, _react.useLayoutEffect)(useEffectFnRef.current, watchValuesRef.current); return props; }; }; exports.onLayout = onLayout; //# sourceMappingURL=on-layout.js.map