reagent

2025-03-13T14:11:27.270799Z

Does reagent process reactive components in select :options? I have (in short) [:select {...} (doall (for [op all-ops] [:option {:key op} [tr-set op]]))] which is creating a dropdown select menu and populating the options with a reagent component (using the vector instead of parentheses). this fills my dropdown with [object Object] instead of reactively rendering them.

✅ 1
p-himik 2025-03-13T14:21:40.140759Z

Of course it should work. doall is not needed as well. Just tested with this:

(defn root-view []
  (r/with-let [options (r/atom [])]
    [:div
     [:button {:on-click #(swap! options (fn [opts]
                                           (let [id (inc (count opts))]
                                             (conj opts {:value id
                                                         :label (str "Option " id)}))))}
      "Add an option"]
     [:select
      (for [{:keys [value label]} @options]
        [:option {:value value
                  :key   value}
         label])]]))

p-himik 2025-03-13T14:22:28.592469Z

If you don't have a lot of options, a slightly simpler way would be to use (into [:select] (map ...) all-ops) - it removes the need for :key.

2025-03-13T14:22:57.113549Z

i'm sorry, i mean a reactive function call: [:option ... [some-func op]]

p-himik 2025-03-13T14:23:10.013819Z

What is some-func?

2025-03-13T14:23:15.983929Z

a function that returns hiccup

2025-03-13T14:23:43.516009Z

lol i just realized why this doesn't work

2025-03-13T14:23:54.251019Z

thank you for rubber ducking 🤦‍♀️

👍 1
p-himik 2025-03-13T14:23:58.896909Z

<option> does not allow for any content other than plain text.

juhoteperi 2025-03-14T09:12:05.962179Z

some-func could probably return some text inside [:<> ...] (fragment) and that should work, but yeah other elements wont work