UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

21 lines 634 B
"use client"; import { useClientLayoutEffect } from "./useClientLayoutEffect.js"; import { useRefWithInit } from "./useRefWithInit.js"; export function useLatestRef(value) { const latest = useRefWithInit(createLatestRef, value).current; latest.next = value; // eslint-disable-next-line react-hooks/exhaustive-deps 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