'use client' // based on https://github.com/Andarist/use-constant import { useRef } from 'react' type ResultBox = { v: T } /** * React hook for creating a value exactly once */ export function useConstant(fn: () => T): T { const ref = useRef | null>(null) if (!ref.current) { ref.current = { v: fn() } } return ref.current.v }