UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

15 lines (11 loc) 313 B
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; };