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.

Targeting another emotion component does not work.

See original GitHub issue

Current behavior:

I am following the docs here in order to target another emotion component. Copying the example does not work as no child component styles are applied.

To reproduce:

https://codesandbox.io/s/emotion-issue-template-ll8py?file=/src/index.js

Expected behavior:

The child component should be green but it’s red.

Environment information:

  • react version: react@16.13.1
  • emotion version: emotion@9.2.6

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
Andaristcommented, Aug 26, 2020

The use of target seems really promising, but can that be used in conjunction with the Babel plugin? I’m guessing not since you dropped the use of the Babel Macros to demonstrate it.

The Babel plugin would probably override the manual target - it literally inserts this target to the code, this is how component selectors are implemented. I’ve just dropped using the Macros because didn’t have time to figure out why they didn’t work on the codesandbox (and they should). So I’ve prepared an equivalent demo without a Babel plugin being used - but it contains very similar code to which Babel plugin transpiles styled components.

3reactions
Andaristcommented, Aug 25, 2020

Ok, I’ve dropped using Babel Macros there as I hadn’t much time to figure out what’s wrong. I’ve prepared an equivalent demo though: https://codesandbox.io/s/emotion-issue-template-forked-odeq5?file=/src/index.js . What Babel plugin does is that it just inserts an option argument with a target property and this can be used manually with success. Can’t reproduce your problem with the project exploding - everything works fine, so you would have to prepare a repository with your issue reproduced so I could take a deeper look at your problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Target another component on hover using emotion-js
Here is my code and what I have tried. import React from 'react'; import styled from '@emotion/styled'; import { Link } from 'gatsby';...
Read more >
Styled Components - Emotion
styled is a way to create React components that have styles attached to them. It's available from @emotion/styled. ... Targeting another emotion component....
Read more >
Style library interoperability - Material UI - MUI
If you are already using a custom theme with styled-components or Emotion, it might not be compatible with MUI's theme specification. If it's...
Read more >
Why We're Breaking Up with CSS-in-JS - DEV Community ‍ ‍
I'm using Emotion with server-side rendering and MUI/Mantine/(another Emotion-powered component library) and it's not working because.
Read more >
The styled-components Happy Path - Josh W Comeau
styled-components is a wonderfully powerful styling library for React, ... Here's another way to solve the problem, using CSS variables:.
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found