Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapping a Seq to Seq[ReactElement] breaks Slinkly #512

Open
3xau1o opened this issue Oct 22, 2021 · 2 comments
Open

mapping a Seq to Seq[ReactElement] breaks Slinkly #512

3xau1o opened this issue Oct 22, 2021 · 2 comments

Comments

@3xau1o
Copy link

3xau1o commented Oct 22, 2021

in react is quite common to map an Array[any] to an Array[React Element], like this

render() {
    return (
      <div>
          {people.map((person, index) => (
              <p>Hello, {person.name} from {person.country}!</p>
          ))}
      </div>
   );
}

unfortunately, slinky breaks when trying to map a Seq[String] to a Seq[ReactElement]

like the following, it doesn't change no matter if you use ascription :*

iconNames = Seq("currency_exchange", "face")
...
  div()(
    iconNames.map(iconName => MaterialIcon(iconName, color="red")): _*
  )

Throwables.scala:18 Uncaught org.scalajs.linker.runtime.UndefinedBehaviorError: java.lang.ClassCastException: undefined is not an instance of scala.collection.immutable.Seq

however, using sequence of react elements directly without mapping works

div())(
  Seq (
    MaterialIcon("face"),
    MaterialIcon("currency_exchange"),
  )
)

image

i wonder if the problem may be caused by implicit conversions and how could a workaround be

@shadaj
Copy link
Owner

shadaj commented Nov 5, 2021

@saulpalv hmm, this is interesting. Perhaps I missed this, but what happens if you pass in the sequence directly without : _*? Although it should work correctly in both cases.

@shadaj
Copy link
Owner

shadaj commented Nov 5, 2021

Oh, wait, just noticed that iconNames is mutable in your example. It seems that iconNames may not have been initialized by the time you use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants