Component-based API for global styling
See original GitHub issueVia https://github.com/styled-components/styled-components/issues/730#issuecomment-320035959
It would be great to have a React component for global styles that does the actual injecting (rendering null), removing the CSS when it is unmounted.
So instead of
injectGlobal`...`
you’d do
const GlobalStyle = styled.global`
… (including prop interpolation)
`
...
return (
<App>
<GlobalStyle darkBg={this.props.dark} />
...
</App>
)
The only differences with regular styled components would be:
- Renders null
- Does not wrap the CSS with an own class
This way:
- Global styles can be easily modified via props
- It works without issues in SSR
- It’s obvious what is happening
Issue Analytics
- State:
- Created 6 years ago
- Reactions:42
- Comments:20 (17 by maintainers)
Top Results From Across the Web
API Reference - styled-components
A helper function to generate a special StyledComponent that handles global styles. Normally, styled components are automatically scoped to a local CSS class ......
Read more >Styled System
Styled System is a collection of utility functions that add style props to your React components and allows you to control styles based...
Read more >Styled Components: Styling for component based application
Here in this piece of code we created a simple animation Loader component using keyframes and psuedo-classes. Styled-component export a keyframes helper ...
Read more >Styles API | Mantine
You can also use Styles API in MantineProvider with styles prop. All styles defined there will be added to each component rendered inside...
Read more >Styling-API Reinvented - Zalando Engineering Blog
This important step in CSS evolution was really necessary for UI components to be used with more confidence. No more global scope causing...
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 Free
Top 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
@imbhargav5 after latest v3 update it just forces me with severity “
error
” to usecreateGlobalStyle
, but I am not sure it’s possible to do in v3.I want to say some kind of deprecations should provide a way to switch on the new feature and to remove that deprecation warning. But currently the deprecation warning doesn’t provide any alternatives to do that without upgrading to v4.
Yeah… I think I’m just going to take it out. After more thought it doesn’t make sense to put in a non-actionable warning.