hello, I'm trying to use some props as a fn call result, like this:
(defn dom-props [{::keys [state] :as props}]
(cond-> (coll/filter-keys simple-keyword? props)
state
(as-> <>
(let [[value set-value!] state]
(assoc <> :value value :on-change #(set-value! (.. % -target -value)))))
true
clj->js))
(defn dom-select
[{::keys [options] :as props}]
(dom/select (dom-props props)
(for [[value label] options]
(dom/option {:value (pr-str value)} (str label)))))
the problem is that Helix thinks that (dom-props props)
is supposed to be a child, not the props
is there a way around this?
I believe you have to use the spread symbol there.
(defn dom-select
[{::keys [options] :as props}]
(dom/select {:& (dom-props props)}
(for [[value label] options]
(dom/option {:value (pr-str value)} (str label)))))
Factory functions also do not have this problem :)
oconn and dominic are correct - when using the dom and $ macros, itโs assumed that props will be written literally. if youโd like to use dynamic props, you can pass a & prop that helix will merge with any of the literally written props
https://github.com/lilactown/helix/blob/master/docs/creating-elements.md#dynamic-props
cool nice, I didn't knew about the {:& ...}
syntax, that works ๐