@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
15 lines (11 loc) • 313 B
text/typescript
import React from "react";
/**
* returns a ref with an initial value that is lazily evaluated once
* */
export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
const ref = React.useRef<T>(null);
if (ref.current === null) {
ref.current = initialValueGetter();
}
return ref;
};