Some checks failed
Build and Test / run-test (20.x) (push) Failing after 1m36s
14 lines
249 B
TypeScript
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 };
|