UNPKG

use-init

Version:

It's sorta like useMemo without your linter yelling at you

13 lines (12 loc) 311 B
import { useRef } from "react"; function useInit(func) { const initRef = useRef({ initialized: false }); if (!initRef.current.initialized) { initRef.current.value = func(); initRef.current.initialized = true; } return initRef.current.value; } export default useInit;