mirror of
https://github.com/supabase/supabase.git
synced 2026-05-08 09:50:33 -04:00
1cd1ebfc7f
Sorted all imports in all packages, `cms`, `design-system` and `ui-library` apps by running `pnpm format` on them. All changes in this PR are done by the script.
20 lines
354 B
TypeScript
20 lines
354 B
TypeScript
'use client'
|
|
|
|
// based on https://github.com/Andarist/use-constant
|
|
import { useRef } from 'react'
|
|
|
|
type ResultBox<T> = { v: T }
|
|
|
|
/**
|
|
* React hook for creating a value exactly once
|
|
*/
|
|
export function useConstant<T>(fn: () => T): T {
|
|
const ref = useRef<ResultBox<T>>()
|
|
|
|
if (!ref.current) {
|
|
ref.current = { v: fn() }
|
|
}
|
|
|
|
return ref.current.v
|
|
}
|