question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlight the importance of using the css helper

See original GitHub issue

Aside 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
chasemccoycommented, Dec 19, 2018

@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 😅

4reactions
mxstbrcommented, Jan 10, 2018

This is such a great point, I think many people miss this fact. I think there’s a couple good first steps:

  1. Make sure the docs and examples are using css everywhere
  2. Have an FAQ entry “Why should I use the css helper over just a string?”
  3. Maybe mention it more often elsewhere in the docs?

Any PRs making this more obvious would be much appreciated! 🙏

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found