Polymorphic Component Element Attributes
Explore how to build polymorphic React components that support element-specific attributes correctly. Understand the limitations of naive implementations and learn how TypeScript helps enforce type safety, preventing invalid HTML and improving developer experience during development and build time.
We'll cover the following...
We'll cover the following...
Introduction
Let's consider the current simple implementation again:
The only props this component accepts are as and children, and nothing else.
There’s no attribute support taken into consideration here. For example, if as were the anchor element a, a consumer should also be able to pass href to the component.
...