Drawbacks of Simple Implementation
Explore the problems with simple polymorphic component implementation.
We'll cover the following
We now have something of a standard polymorphic implementation. However, our implementation has a few problems. One of those problems is that the polymorphic prop can receive invalid HTML elements.
For example, it's currently possible for a user to go ahead and write something like the following:
<PolymorphicText as="educative">Hello Wrong Element</PolymorphicText>
Passing a wrong as attribute
The as
prop passed here is educative
.
The educative
prop is obviously an incorrect HTML element, but the browser still tries to render it.
Inspecting the rendered element
Click the "Run" button and inspect the element rendered in the playground widget below.