For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/react/Function.useRef.md.
  • English
  • @lynx-js/react / useRef

    Function: 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.

    Type Parameters

    Type Parameter
    T

    Parameters

    ParameterType
    initialValueT

    Returns

    MutableRefObject<T>

    Version

    16.8.0

    See

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

    Defined in

    .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.

    Type Parameters

    Type Parameter
    T

    Parameters

    ParameterType
    initialValuenull | T

    Returns

    RefObject<T>

    Version

    16.8.0

    See

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

    Defined in

    .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.

    Type Parameters

    Type ParameterDefault type
    Tundefined

    Parameters

    ParameterType
    initialValue?undefined

    Returns

    MutableRefObject<T | undefined>

    Version

    16.8.0

    See

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

    Defined in

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

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.