Fork me on GitHub
#reagent
<
2021-10-09
>
Schpaa09:10:05

I have a simple react-component that takes some variable number of args, like this:

[(r/adapt-react-class Stuff)
 {:args :whatever}
 [item1]
 [item2]
 [item3]]
Now, I want to supply those items as a list, how can I use apply (for instance) to make this work?

Schpaa09:10:34

Just to be clear, I want to achieve something along the following

(let [items [[item1][item2][item3]]] 
 [(r/adapt-react-class Stuff)
  {:args :whatever}
  ...items?...]

p-himik09:10:51

Use into. Also, you can replace (r/adapt-react-class Stuff) with :> Stuff. Alternatively, move (r/adapt-react-class Stuff) to an outer def to avoid calling that function on each render (the function is cheap, but it's still an extra call).

😀 1
p-himik09:10:14

And if items is a real list and not a vector, you can just supply it as is. React might complain about a missing :key (not sure if that's only for lazy collections or for regular lists as well). In that case, either provide :key if it's possible to use an organic key and not a synthetic one, or just use into.

Schpaa09:10:43

Thank you so much!

👍 1