Fork me on GitHub
#helix
<
2020-10-27
>
wilkerlucio20:10:49

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

wilkerlucio20:10:13

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

wilkerlucio20:10:17

is there a way around this?

oconn20:10:21

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

👍 3
dominicm21:10:05

Factory functions also do not have this problem :)

lilactown21:10:22

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

wilkerlucio22:10:36

cool nice, I didn't knew about the {:& ...} syntax, that works 👍