`as` removes bases styles for functional/class components
See original GitHub issueEnvironment
System:
- OS: macOS 10.14.2
- Shell: 5.3 - /bin/zsh
Binaries:
- Node: 8.9.0
- Yarn: 1.12.3
npmPackages:
- babel-plugin-styled-components: 1.5.1 => 1.5.1
- styled-components: 4.1.2 => 4.1.2
Reproduction
https://codesandbox.io/s/30k0n99jv5
Steps to reproduce
- Create Styled-Component
- Use the Styled-Component in a functional component (be sure to pass down your props to the styled-component)
- Extend functional component with some additional styles
- Use your extended version of the component with the
as
as prop
Expected Behavior
- Base styles should still be applied
- Extended styles should be applied overtop of base styles
- New tag is used
Actual Behavior
- Base styles are dropped, and only the extended styles are applied
- New tag is still properly applied.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Functional vs Class Components in React Native
In React Native, there are two main types of components that make up an application: functional components and class components.
Read more >React Class Component vs Functional Component - Telerik
If you're a React developer or new to React, this article clears up some of the confusion between these two types of components...
Read more >How To Style React Components | DigitalOcean
In this tutorial, you'll learn three different ways to style React components: plain Cascading Style Sheets (CSS), inline styles with ...
Read more >Understanding Functional Components vs. Class ... - Twilio
This article will help you understand the differences between functional and class components by walking through each one with sample code ...
Read more >How To Use Styled-Components In React - Smashing Magazine
Adapting Based on Props #. Styled components are functional, so we can easily style elements dynamically. Let's assume we have two types of ......
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
I’m seeing this on 4.1.3 as well.
Headline.js:
StyledHeadline.js:
When I use
StyledHeadline
with theas
prop, the only styles applied arecolor: pink;
.I encountered this issue too.
In case of use styled-component for the UI-library that has internally gives className, and using
as
option will behave exactly as the pasted by guys the examples. This could not keep the appearance as enough UI component.I read styled-component’s source code a little. For now, I just found behavior is below.
https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/models/StyledComponent.js#L135
https://github.com/styled-components/styled-components/blob/master/packages/styled-components/src/models/StyledComponent.js#L172
Is it generated another element when use
as
? Which means, Even if can be passed enough props object bypropsForElement
, the internal logic by the component itself that is originally passed as atarget
is not executed.If the classNames within a component are internally generated by different architectures such as
classnames
, the component will be destroyed when use withas
.Is
as
use case only use to the primitive element?This is might become a stall point when use styled-component with some UI library. Also, this may be breaking if the UI library has props of the same name (
as
).If my understanding is not wrong, the best workaround is … “Take care when use
as
option” 🤕 Can I know the contributor’s opinion about this?cc: @probablyup @leerob thanks for your example, It is easy to understand.