Highlight the importance of using the css helper
See original GitHub issueAside from being a nice tool for organizing/reusing css in different ways, we all know that css helper is also needed to nest interpolations etc…
I think that it would be helpful for those learning sc for the first time to encounter examples and notes early on about the importance of the css helper. Perhaps we could even stress using it regularly as a best practice, especially as it sounds like it will be more and more essential with minification, analysis, etc…
Preferring:
const StyledDiv = styled.div`
background: #00f;
${({myProp}) => myProp && css`
padding: 10px;
`}
`
Over:
const StyledDiv = styled.div`
background: #00f;
${({myProp}) => myProp && `
padding: 10px;
`}
`
Much of this is already discussed in: https://github.com/styled-components/styled-components/issues/1178, but I wanted to open an issue to discuss how we could surface some of this into the docs.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:12 (6 by maintainers)
Top Results From Across the Web
What is CSS, and why is it important? - BigCommerce
CSS stands for Cascading Style Sheets. It is the coding language that gives a website its look and layout. Along with HTML, CSS...
Read more >CSS !important Property - W3Schools
The !important rule in CSS is used to add more importance to a property/value than normal. In fact, if you use the !important...
Read more >How to Use the !important Property in CSS - HubSpot Blog
In CSS, important means that only the !important property value is to be applied to an element and all other declarations on the...
Read more >What Is CSS and its Importance in Web Development
It is a highly effective tool HTML that provides easy control over layout and presentation of website pages by separating content from design....
Read more >9 Great benefits to using CSS3 - CSS Reset - CSSDeck
Backgrounds are made exciting by the help of CSS3. It allows designers to choose from multiple backgrounds which can be applied with ease....
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 Hashnode Post
No results found
Top GitHub Comments
@alaskaa Any updates on this?
@mxstbr I consider myself a pretty advanced styled-components user (have used it for years and in many projects), and I spent the entire day today trying to figure out why my components were behaving in weird ways when I realized that I had forgot to use the
css
tag on some nested interpolations. I read back through the docs, and sure enough it’s not mentioned anywhere other than in the API reference (from what I can see).It would be great to document this more (I would be happy to make a PR!), but I also think it would be awesome to somehow lint or warn against this. The type of bugs that can result from this error (or at least the ones I ran into) are extremely hard to debug and there’s no indication that the user is doing something wrong when they use an interpolation without the helper. Just something to consider, it may save someone some time in the future. It definitely would have saved me some 😅
This is such a great point, I think many people miss this fact. I think there’s a couple good first steps:
css
everywherecss
helper over just a string?”Any PRs making this more obvious would be much appreciated! 🙏