UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

15 lines 766 B
import { useCallback, useEffect, useRef } from "react"; /** * A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a * prop or avoid re-executing effects when passed as a dependency * https://github.com/radix-ui/primitives/blob/main/packages/react/use-callback-ref/src/useCallbackRef.tsx */ export function useCallbackRef(callback, deps = []) { const callbackRef = useRef(callback); useEffect(() => { callbackRef.current = callback; }); // eslint-disable-next-line react-hooks/exhaustive-deps return useCallback(((...args) => { var _a; return (_a = callbackRef.current) === null || _a === void 0 ? void 0 : _a.call(callbackRef, ...args); }), deps); } //# sourceMappingURL=useCallbackRef.js.map