File size: 306 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
"use client"
import { useRef } from "react"
type InitFn<T> = () => T
export function useConst<T extends any>(init: T | InitFn<T>): T {
const ref = useRef(null)
if (ref.current === null) {
// @ts-ignore
ref.current = typeof init === "function" ? init() : init
}
return ref.current as T
}
|