13 lines
304 B
TypeScript
13 lines
304 B
TypeScript
import type { MutableRefObject } from "react";
|
|
import { useRef } from "react";
|
|
|
|
const useLazyRef = <T>(initialValFunc: () => T) => {
|
|
const ref: MutableRefObject<T | null> = useRef(null);
|
|
if (ref.current === null) {
|
|
ref.current = initialValFunc();
|
|
}
|
|
return ref;
|
|
};
|
|
|
|
export default useLazyRef;
|