react / 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.
Type Parameter |
---|
T |
Parameter | Type |
---|---|
initialValue |
T |
MutableRefObject
<T
>
16.8.0
https://react.dev/reference/react/useRef
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:1986
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.
Usage note: if you need the result of useRef to be directly mutable, include | null
in the type
of the generic argument.
Type Parameter |
---|
T |
Parameter | Type |
---|---|
initialValue |
null | T |
RefObject
<T
>
16.8.0
https://react.dev/reference/react/useRef
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:2001
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 Parameter | Default type |
---|---|
T |
undefined |
MutableRefObject
<T
| undefined
>
16.8.0
https://react.dev/reference/react/useRef
.pnpm/@types+react@18.3.11/node_modules/@types/react/ts5.0/index.d.ts:2014