Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: polymorphic component #211

Merged
merged 2 commits into from
Nov 9, 2023
Merged

Conversation

nlkluth
Copy link
Member

@nlkluth nlkluth commented Nov 9, 2023

What

Adds Polymorphic types for components

Why

To be more generic, allowing as prop for rendering.

Example

Turn a component that renders a button into a link with as="a". All of the HTMLAnchorElement types now show and are allowed.
Screenshot 2023-11-09 at 10 45 26 AM

See also

  1. https://www.benmvp.com/blog/polymorphic-react-components-typescript/
  2. https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/

Copy link

vercel bot commented Nov 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextjs-sanity-fe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 9, 2023 7:39pm

Copy link
Member

@scottrippey scottrippey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great approach, encapsulates the complexity nicely.

@nlkluth nlkluth merged commit 28f0271 into main Nov 9, 2023
5 checks passed
@nlkluth nlkluth deleted the refactor/polymorphic-component-types branch November 9, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants