Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

useRef

useRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.

Note that useRef() is useful for more than the ref attribute. It’s handy for keeping any mutable value around similar to how you’d use instance fields in classes.

function useRef<T>(initialValue: T): MutableRef<T>;
function useRef<T>(initialValue: T | null): Ref<T>;
function useRef<T = undefined>(): MutableRef<T | undefined>;
§
useRef<T>(initialValue: T): MutableRef<T>
[src]

useRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.

Note that useRef() is useful for more than the ref attribute. It’s handy for keeping any mutable value around similar to how you’d use instance fields in classes.

§Type Parameters

§Parameters

§
initialValue: T
[src]

the initial value to store in the ref object

§Return Type

§
MutableRef<T>
[src]
§
useRef<T>(initialValue: T | null): Ref<T>
[src]

§Type Parameters

§Parameters

§
initialValue: T | null
[src]

§Return Type

§
Ref<T>
[src]
§
useRef<T = undefined>(): MutableRef<T | undefined>
[src]

§Type Parameters

§
T = undefined
[src]

§Return Type

§
MutableRef<T | undefined>
[src]