A wrapper around React.forwardRef() that allows HTML attributes and prop types to be derived from the as prop.
npm install forward-ref-as
A wrapper aroundReact.forwardRef()that allows HTML attributes and prop types to
be inferred from anasprop.
npm i forward-ref-as
``tsx
import forwardRefAs from 'forward-ref-as'
// Forwards ref to the underlying button and adds strongas
// types for the prop.
const Button = forwardRefAs<'button', ButtonProps>(
({as: As = 'button', ...props}, ref) =>
)
// ✅ Will pass type checking and autocomplete correctly
;
`
A wrapper around React.forwardRef() with the same call signature, butas` prop HTML attributes and React prop types
a type signature that allows
to be inferred.
MIT