https://github.com/jaredlunde/forward-ref-as
A wrapper around React.forwardRef() that allows HTML attributes and prop types to be derived from the "as" prop.
https://github.com/jaredlunde/forward-ref-as
as-prop forwardref polymorphic polymorphic-component react react-utils
Last synced: 5 months ago
JSON representation
A wrapper around React.forwardRef() that allows HTML attributes and prop types to be derived from the "as" prop.
- Host: GitHub
- URL: https://github.com/jaredlunde/forward-ref-as
- Owner: jaredLunde
- License: mit
- Created: 2020-07-25T17:00:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T12:26:07.000Z (almost 3 years ago)
- Last Synced: 2024-08-08T22:52:03.842Z (over 1 year ago)
- Topics: as-prop, forwardref, polymorphic, polymorphic-component, react, react-utils
- Language: TypeScript
- Homepage:
- Size: 2.26 MB
- Stars: 23
- Watchers: 3
- Forks: 1
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
forwardRefAs()
A wrapper around React.forwardRef() that allows HTML attributes and prop types to
be inferred from an as prop.
npm i forward-ref-as
## Quick start
```tsx
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) =>
)
// ✅ Will pass type checking and autocomplete correctly
;
```
## 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