Files
hideyoshi-blog/src/ui/hooks/use-lazy-ref.ts
Vitor Hideyoshi 3f9613d98b
Some checks failed
Build and Test / run-test (20.x) (push) Failing after 1m36s
WIP
2026-04-09 20:57:35 -03:00

14 lines
249 B
TypeScript

import * as React from 'react';
function useLazyRef<T>(fn: () => T) {
const ref = React.useRef<T | null>(null);
if (ref.current === null) {
ref.current = fn();
}
return ref as React.RefObject<T>;
}
export { useLazyRef };