15 lines
335 B
TypeScript
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;
|