UNPKG

630 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _react = require("react");
8var defaultShouldUpdate = function defaultShouldUpdate(a, b) {
9 return !Object.is(a, b);
10};
11function usePrevious(state, shouldUpdate) {
12 if (shouldUpdate === void 0) {
13 shouldUpdate = defaultShouldUpdate;
14 }
15 var prevRef = (0, _react.useRef)();
16 var curRef = (0, _react.useRef)();
17 if (shouldUpdate(curRef.current, state)) {
18 prevRef.current = curRef.current;
19 curRef.current = state;
20 }
21 return prevRef.current;
22}
23var _default = usePrevious;
24exports["default"] = _default;
\No newline at end of file