Hello 🙂
What React wrapper would you recommand between reagent
, uix
and helix
?
reagent (& re-frame) are usually what I go with, and what I mostly see others use for react-based cljs front-ends
How does one explode a vector into args for multi-arity js functions?
I stumbled across https://stackoverflow.com/questions/41190807/in-clojurescript-how-do-i-pass-a-collections-elements-as-arguments-to-a-variab. The discussed example works just fine in my cljs repl using apply
.
But, I can't seem to apply (pun intended) the same logic to some other js functions like Array.push
i.e. (def a (js/Array.)) (apply (.-push a) [1 2])
doesn't work for me and throws #object[TypeError TypeError: Cannot assign to read only property 'length' of function 'function push() { [native code] }']
It's moments like this where I wish cljs just supported the js spread operator i.e. ...
- I don't think it's that far of a cry from the dots and dashes one already has to use for interop.
hmm I'm not sure about that error yet (I can repro I just don't know why) but you can also use .apply
and the prototype method:
(.apply js/Array.prototype.push a (to-array [1 2]))
this is equivalent to the JS code:
Array.prototype.push.apply(a, [1, 2])
Ah, thanks! It works : - ) Forgot about the js apply function.
If you prefer thin wrappers then helix
. If you prefer to have some nice things at the cost of more abstractions, then reagent
. Can't say anything about uix
- haven't used it.
I almost always use reagent
as well.
Hint: it works if you wrap (.-push a)
in (.bind ... a)
. :)
Array.prototype.push
requires some this
. (.-push a)
is unbound.