Can we use styled components export className ?
See original GitHub issueConsider the following code:
const Wrapper = styled.div`
&-icon {
color: #fff;
}
`
render() {
const cls = Wrapper.getClassName();
return <Wrapper>
<div className={`${cls}-icon`}>xxx</div>
</Wrapper>
}
This saves a lot on the definition of the styled component。
Issue Analytics
- State:
- Created 5 years ago
- Reactions:12
- Comments:20
Top Results From Across the Web
Advanced Usage - styled-components
styled -components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components underneath ...
Read more >Pass Styled component as className to another component
Styled components will "wrap" around the base component and try to pass styles to it. Most library components should work with this but...
Read more >How to Control Class Names in Styled Components
Internally, styled-components generates two classes for each component— one is static and one is dynamic. The class name is generated by ...
Read more >How To Use React Styled Components Efficiently - Copycat
Using styled-components makes it simple to use actual CSS to style components by writing JavaScript code. These components are known as “styled ...
Read more >Style library interoperability - Material UI - MUI
Note: If you are using styled-components and have StyleSheetManager with a custom target , make sure that the target is the first element...
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
Same issue, the use case is we need assign a classname to a 3rd UI library to some sub component, eg:
Hi @d640k
You can convert a styled-component to a string to retrieve it’s CSS Selector: