mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
15 lines
306 B
TypeScript
15 lines
306 B
TypeScript
import { useRef } from 'react'
|
|
|
|
/**
|
|
* Once a non-undefined value is passed, it will never change.
|
|
*/
|
|
export function useImmutableValue<T>(value: T | undefined): T | undefined {
|
|
const ref = useRef<T | undefined>(value)
|
|
|
|
if (!ref.current && value) {
|
|
ref.current = value
|
|
}
|
|
|
|
return ref.current
|
|
}
|