2.0.0 • Published 3 years ago

forward-ref-as v2.0.0

Weekly downloads
544
License
MIT
Repository
github
Last release
3 years ago

Quick start

import forwardRefAs from 'forward-ref-as'

// Forwards `ref` to the underlying button and adds strong
// types for the `as` prop.
const Button = forwardRefAs<'button', ButtonProps>(
  ({as: As = 'button', ...props}, ref) => <As ref={ref} {...props} />
)

// ✅ Will pass type checking and autocomplete correctly
;<Button as='a' href='https://jaredLunde.com' />

API

forwardRefAs()

A wrapper around React.forwardRef() with the same call signature, but a type signature that allows as prop HTML attributes and React prop types to be inferred.

LICENSE

MIT