cal.pub0.org/packages/lib/hooks/useCallbackRef.ts

15 lines
335 B
TypeScript

import { useRef } from "react";
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect";
export const useCallbackRef = <C>(callback: C) => {
const callbackRef = useRef(callback);
useIsomorphicLayoutEffect(() => {
callbackRef.current = callback;
});
return callbackRef;
};
export default useCallbackRef;