Function useForwardedRef

  • Custom React hook that creates a ref and forwards its value to a parent component.

    This hook allows you to handle refs in a way that supports both internal and external access to the ref value. It uses useImperativeHandle to expose the current value of the ref to the parent component when using forwardRef.

    Example

    const MyComponent = forwardRef((props, ref) => {
    const internalRef = useForwardedRef(ref);

    return <div ref={internalRef}>Hello, World!</div>;
    });

    Type Parameters

    • T

    Parameters

    • forwardedRef: undefined | ForwardedRef<T>

      The forwarded ref from the parent component.

    Returns RefObject<T>