Back to all questions
Why I cannot use one polymorphic component in component prop of another polymorphic component?
Last updated
What is polymorphic component?
A polymorphic component is a component which root element can be changed with component prop.
All polymorphic components have a default element which is used when component prop is not provided.
For example, the Button
component default element is button
and it can be changed to
a
or any other element or component:
Polymorphic components types
Polymorphic components types are defined by the type of the root element which is not known until the component is used.
Example:
Why I cannot use one polymorphic component in component prop of another polymorphic component?
When you use one polymorphic component in component
prop of another polymorphic component,
types cannot be inferred correctly because the type of the root element is not known until the component is used.