The props any component accepting refs can receive.
Class components, built-in browser components (e.g. div) and forwardRef components can receive refs and automatically accept these props.
Otherwise it's simpler to directly use Ref since you can safely use the
props type to describe to props that a consumer can pass to the component
as well as describing the props the implementation of a component "sees".
RefAttributes is generally not safe to describe both consumer and seen props.
WARNING: The implementation of a component will not have access to the same type in versions of React supporting string refs.
The following example would be incorrect usage because Component would never have access to a ref with type string
Allows getting a ref to the component instance.
Once the component unmounts, React will set ref.current to null
(or call the ref with null if you passed a callback ref).
The props any component accepting refs can receive. Class components, built-in browser components (e.g.
div
) and forwardRef components can receive refs and automatically accept these props.You only need this type if you manually author the types of props that need to be compatible with legacy refs.
Otherwise it's simpler to directly use Ref since you can safely use the props type to describe to props that a consumer can pass to the component as well as describing the props the implementation of a component "sees". RefAttributes is generally not safe to describe both consumer and seen props.
WARNING: The implementation of a component will not have access to the same type in versions of React supporting string refs. The following example would be incorrect usage because Component would never have access to a
ref
with typestring