@lynx-js/react / useRef

函数: useRef()

useRef(initialValue)

function useRef<T>(initialValue: T): MutableRefObject<T>

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.

类型参数

类型参数
T

参数

范围类型
initialValueT

返回

MutableRefObject<T>

Version

16.8.0

参阅

https://react.dev/reference/react/useRef

定义于

.pnpm/@types+react@18.3.28/node_modules/@types/react/ts5.0/index.d.ts:1994

useRef(initialValue)

function useRef<T>(initialValue: null | T): RefObject<T>

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.

类型参数

类型参数
T

参数

范围类型
initialValuenull | T

返回

RefObject<T>

Version

16.8.0

参阅

https://react.dev/reference/react/useRef

定义于

.pnpm/@types+react@18.3.28/node_modules/@types/react/ts5.0/index.d.ts:2009

useRef(initialValue)

function useRef<T>(initialValue?: undefined): MutableRefObject<T | undefined>

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.

类型参数

类型参数默认类型
Tundefined

参数

范围类型
initialValue?undefined

返回

MutableRefObject<T | undefined>

Version

16.8.0

参阅

https://react.dev/reference/react/useRef

定义于

.pnpm/@types+react@18.3.28/node_modules/@types/react/ts5.0/index.d.ts:2022

除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。