`as` prop causes TypeError when wrapping components
See original GitHub issueCurrent behavior:
as
prop causes TypeError for components utilizing that prop wrapped in styled()
To reproduce:
https://codesandbox.io/s/quizzical-kalam-xvgve?from-embed=&file=/src/App.tsx
Expected behavior:
I guess CreateStyled
shouldn’t extend props with as
prop for all cases extending components. (only for IntrinsicElements)
Environment information:
react
version: latest@emotion/react
version: latest
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
reactjs - Why does Route with children as components cause ...
When rendering on the component prop, the route props are passed along, so props.match.params works, but now you can't pass the additional ...
Read more >HOC props are required to be present in wrapped component ...
When using the new way of typing HOC's in v0.53.0, it is required that all injected properties are present in the Props definition...
Read more >Why do we have to wrap React components? | by Aaron S
Syntax error: Adjacent JSX elements must be wrapped in an enclosing ... elementType — The HTML Tag you want to display; props —...
Read more >A better way of solving prop drilling in React apps
In the spirit of "using the platform," learn how the React library provides a workaround for prop drilling without Redux or the Context...
Read more >Error Boundaries - React
In the past, JavaScript errors inside components used to corrupt React's internal state and cause it to emit cryptic errors on next renders....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, this is impossible/hard. If one wants to add support for
as
prop for their wrapped custom components then they can do this manually.That’s fine - this should usually be a rare situation and the full relation between input props,
shouldForwardProp
and the forwarded props is not validated anyway.That aligns with my current way of thinking about this - please only make sure to add some basic tests for the expected behavior.
Not sure what kind of fix you have in mind. 😅
yeah, that’s the current behaviour, but I don’t think it is possible to conditionally change the TypeScript typing based on passing something like
shouldForwardProp: prop => prop !== 'as'
.I could do that utilising some additional prop, like
shouldForwardAsProp
, but it’s stupid.The only solution I can think of right now is not adding the
as
prop to the type when wrapping composite components, but that will result in wrong typing when you pass theshouldForwardProp
as above.But on the other hand, are there any real-life examples of needing to render composite component
as
a html tag? You lose all the functionality of the wrapped component, the typing is probably wrong in most cases, as your wrapped component is probably using some fancy props, which are not applicable to html tags.So I suggest removing the
as
prop from type definitions for composite components completely. Any thoughts?