UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

24 lines 792 B
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useLatestRef = useLatestRef; const useClientLayoutEffect_1 = require("./useClientLayoutEffect"); const useRefWithInit_1 = require("./useRefWithInit"); function useLatestRef(value) { const latest = (0, useRefWithInit_1.useRefWithInit)(createLatestRef, value).current; latest.next = value; // eslint-disable-next-line react-hooks/exhaustive-deps (0, useClientLayoutEffect_1.useClientLayoutEffect)(latest.effect); return latest; } function createLatestRef(value) { const latest = { current: value, next: value, effect: () => { latest.current = latest.next; }, }; return latest; } //# sourceMappingURL=useLatestRef.js.map