Spreading className prop results in [object Object]
See original GitHub issueemotion
version: 10.0.4react
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:
- Created 5 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top 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 >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
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