Files
supabase/packages/common/hooks/useConstant.ts
T
Alaister Young 9d8e8b068f chore: move role impersonation state into a context (#19510)
* chore: move role impersonation state into a context

* clean up ProjectContext.tsx imports

* move isRoleImpersonationEnabled to only relevant queries
2023-12-11 16:32:11 +11:00

19 lines
341 B
TypeScript

// 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
}