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.

Spreading className prop results in [object Object]

See original GitHub issue
  • emotion version: 10.0.4
  • react version: 16.7.0-alpha.2
const linkCss = css`
  color: black;

  &.active-section {
    color: red;
  }
`

function setClass({ href, isPartiallyCurrent }) {
  if (isPartiallyCurrent && href !== '/') {
    return {
      className: `${linkCss} active-section`,
    }
  }

  return {
    className: linkCss,
  }
}

<Link getProps={setClass} />

I’m migrating from Emotion 9 to 10, on a Gatsby site. The above (simplified) code used to work:

<a class="css-RANDOMHASH>

// or, when applicable
<a class="css-RANDOMHASH active-section">

After the migration, css-RANDOMHASH is replaced by [object Object]. Does anyone know a fix?

Further information: This uses the getProps API from @reach/router. Source here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mnpennercommented, May 16, 2019
import { css as cssClass } from 'emotion';

Doesn’t exist in emotion 10. What’s the proper way to do this now?

0reactions
TarVKcommented, Aug 16, 2019
import { css as cssClass } from 'emotion';

Doesn’t exist in emotion 10. What’s the proper way to do this now?

https://emotion.sh/docs/class-names seems like this is the solution now if you want to obtain a class name

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - ClassName is not being passed to Objects
You are passing an object to className , while it expects a string. I think what you are looking for is classnames, which...
Read more >
JSX Spread Operator <Component {…props} /> Meaning
Spread Attributes. If you already have props as an object, and you want to pass it in JSX, you can use ... as...
Read more >
JSX In Depth
This behavior is just there so that it matches the behavior of HTML. Spread Attributes. If you already have props as an object,...
Read more >
A Little Bit of JavaScript: classnames
Use of the spread operator gathers one or more arguments into an array referenced by the classnames variable. return classnames .map(item => { ......
Read more >
Style React Components with className and In Line Styles
If we were to extract these props into an object like this then spread them out on the div, we'd get the same...
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