Fork me on GitHub
#reagent
<
2019-07-22
>
FiVo12:07:42

I am getting a warning: The same with-let is being used more than once in the same reactive context.

FiVo12:07:36

I want to use some component multiple times. Is this not possible with a reagent/with-let?

FiVo13:07:39

(re-frame/reg-event-db
 ::test-add
 (fn [_ [_ cnt]]
   (swap! cnt inc)))

(defn test2 [id]
  (reagent/with-let [cnt (reagent/atom 1)]
    [:div {:id id}
     (for [i (range @cnt)]
       (str "Hello for the " (str i) "th time."))
     [:button
      {:on-click #(re-frame/dispatch [::test-add cnt])}
      "Click me!"]]))

(defn main-form []   ;; works
  (test2 (str "test1")))

(defn main-form []   ;; doesn't works
  (for [i (range 3)]
    (test2 (str "test" (str i)))))

lilactown15:07:14

@finn.volkel try wrapping your test2 component in a vector like [test2 (str “test” i)] rather than call it as a function

FiVo07:07:01

That doesn't work either. I then just get 3 strings like so test0test1test2.

lilactown15:07:33

you wrote your main-form like:

(defn main-form []   ;; doesn't works
  (for [i (range 3)]
    [test2 (str "test" (str i))]))
?

lilactown14:07:27

I’d have to see all the code