@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
20 lines • 706 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePrevious = void 0;
const react_1 = require("react");
/*
* usePrevious hook
* The ref object's "current" property is mutable and when changed wont re-render the component
* meaning it can be used to stay "one render behind" the current state
* https://usehooks.com/usePrevious/
* https://blog.logrocket.com/accessing-previous-props-state-react-hooks/
*/
const usePrevious = (value) => {
const ref = (0, react_1.useRef)(value);
(0, react_1.useEffect)(() => {
ref.current = value;
}, [value]);
return ref.current;
};
exports.usePrevious = usePrevious;
//# sourceMappingURL=usePrevious.js.map