Home > @lndsld/react-hooks > useForwardedRef
Make proxy for ForwardedRef
Signature:
declare function useForwardedRef<T>(forwardedRef: ForwardedRef<T> | undefined): RefObject<T>;
Parameter | Type | Description |
---|---|---|
forwardedRef | ForwardedRef<T> | undefined |
Returns:
RefObject<T>
import { forwardRef, useEffect } from 'react';
const Component = forwardRef((props, forwardedRef) => {
const ref = useForwardedRef(forwardedRef);
useEffect(() => {
ref.current?.focus()
}, [ref])
return <input type="text" ref={ref} />
})