helix

https://github.com/Lokeh/helix
wilkerlucio 2020-10-27T20:23:49.083800Z

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)))))

wilkerlucio 2020-10-27T20:24:13.083900Z

the problem is that Helix thinks that (dom-props props) is supposed to be a child, not the props

wilkerlucio 2020-10-27T20:24:17.084100Z

is there a way around this?

oconn 2020-10-27T20:54:21.084300Z

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)))))

๐Ÿ‘ 1
dominicm 2020-10-27T21:06:05.084500Z

Factory functions also do not have this problem :)

lilactown 2020-10-27T21:39:22.086200Z

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

wilkerlucio 2020-10-27T22:09:36.086800Z

cool nice, I didn't knew about the {:& ...} syntax, that works ๐Ÿ‘