Im recently using reagent and re-frame for my clojurescript project and i have a problem: So i have html custom tags
<question id="1"></question>
<question id="2"></question>
And i want to swap them into my reagent-generated html using cljs for function
(defn mypanel []
[:p "Hi!"])
(let [q (.getElementsByTagName js/document "question")]
(for [i (range 2)]
^{:keys i}
(reagent/render [mypanel]
(aget (.getElementsByTagName js/document "question") i))))
But it doesn't work, i tried to test it without using the for function by
(reagent/render [mypanel]
(aget (.getElementsByTagName js/document "question") 0))
and it worked just fine with only one tag.
And i don't know why the for function doesn't work, or does reagent doesn't work that way? Anybody have a suggestion?
I'm very noob at this.
for
produces a lazy sequence, which means that none of the work to evaluate the sequence is done until it is required. You can't use lazy sequences to force side effects, as they will never be evaluated (render
is one such place). To force side effects you should probably replace it with doseq
. And in your case dotimes
would probably be better:
(let [q (.getElementsByTagName js/document "question")]
(dotimes [i 2]
^{:keys i}
(reagent/render [mypanel]
(aget (.getElementsByTagName js/document "question") i))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With