className interpolation alternative
See original GitHub issueemotion
version: 10.0.6react
version: 16.8.0-alpha.1
Relevant code:
import { css } from 'emotion';
const childClass = css`
display: none;
`;
const containerClass = css`
&:hover .${childClass} {
display: block;
}
`;
const Home = () => (
<div className={containerClass}>
<h1>Hello world</h1>
<div className={childClass}>Hi there!</div>
</div>
);
Problem description:
Hello, I’m getting a warning that class interpolation will not be supported in the next major release of Emotion, but I didn’t find any migration instructions for it and I’m not sure how to implement the example above without interpolation and without using “regular” class names.
I know its use is problematic when using it with composition, but I also don’t know about the alternative in the use cases like the one above. Does the warning mean the feature will be removed or does it mean it will be undocumented in 11 and there will be no guarantees after that (could be removed without notice)?
Issue Analytics
- State:
- Created 5 years ago
- Comments:28 (8 by maintainers)
Top Results From Across the Web
LESS class name string interpolation not working
I am currently translating my grid into LESS, but I can't seem to figure out string interpolation.
Read more >Features In-Depth | Less.js
Less extends CSS with dynamic behavior such as variables, mixins, operations and functions. Less runs on both the server-side (with Node.js and Rhino)...
Read more >Interpolation - Sass
Interpolation can be used almost anywhere in a Sass stylesheet to embed the result of a SassScript expression into a chunk of CSS....
Read more >String Interpolation in JavaScript - Dmitri Pavlutin
String interpolation is replacing placeholders with values in a string literal. The string interpolation in JavaScript is performed by ...
Read more >Guide to String Interpolation With React - Stack Abuse
Depending on the state, a different className will thus be applied to the heading! With concatenation, we will first place our actual string...
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
The easiest way is to use attributes or class names as you would before.
Class Names
Attributes
Note that this works for any version of emotion. If the className is not recognized by emotion it will simply be appended to the className prop.
Sorry, we don’t plan to bring back support for this - truth to be told we don’t believe using any descendant selectors is a good idea. It’s sometimes convenient - that’s for sure, but it makes for a tightly coupled styles which are harder to maintain over the long period of time.
And we are not alone with that. Let’s take a look at a recent post by Facebook - https://engineering.fb.com/web/facebook-redesign/ . We can find this there:
If you really need to target a descendant element with emotion the best you can do is to use data attributes to select them, but again - we don’t recommend this.