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.

Can't pass array to css prop

See original GitHub issue

Hi. I’m having trouble passing an array to css prop. This is the webpack message: “Module not found: Error: Can’t resolve ‘@emotion/css’ in …”

Can someone try to reproduce it? Is this a bug? Here’s a sample:

import React from 'react'
import ReactDOM from 'react-dom'
import {css} from '@emotion/core'

function Test() {
  var c1 = css`color: hotpink;`
  var c2 = css`background-color: lightgray;`
  var c3 = [c1, c2] 

  return <div css={c3}>OLA</div> // this works fine

  //   return <div css={[c1, c2]}>OLA</div> // this one doesn't work
}

ReactDOM.render(
  <Test/>,
  document.getElementById('root')
)

Thanks

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Andaristcommented, Nov 22, 2019

Ok, I see the problem. I have a piece of bad news and a piece of good news - the bad news is that we are unable to fix it, the good news is that we have already fixed it in https://github.com/emotion-js/emotion/pull/1600 😉 The fix is going to only hit upcoming v11 though, we can’t easily backport it to v10.

v11 is very much usable (this change has not been released yet, but if you like - I can do it) and changes since v10 are minor (and we don’t plan to introduce major breaking changes anyway) but depending on the size of your project upgrade might take from 0 to some time (before final release we plan to prepare codemods which will help to migrate automatically, but they are not ready yet).

A workaround for v10 would be to do this:

import {css} from '@emotion/core'

<div css={css([c1, c2])}>OLA</div> 
0reactions
Andaristcommented, Nov 29, 2019

Closing because there is not much we can do about this in v10 as described above. I hope you understand.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not pass array with objects as prop in react - Stack Overflow
The problem I experience is that questions from state can not get the passed as prop. I keep getting empty array for questions...
Read more >
Pass an Array as Props - React - Free Code Camp - YouTube
In this React tutorial we pass an array as props. This video constitutes one part of many where I ... Your browser can't...
Read more >
Passing Arrays as Function Arguments | SamanthaMing.com
If you want to pass an array into a variadic function. You can use ES6 spread to turn that array into a list...
Read more >
Displaying Data with Props - From JavaScript to React - Next.js
If you run this code, React will give us a warning about a missing key prop. This is because React needs something to...
Read more >
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
syntax allows an iterable, such as an array or string, ... In an object literal, the spread syntax enumerates the properties of an...
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