Fork me on GitHub
#reagent
<
2018-08-05
>
henrik06:08:59

@eoliphant This is from the stuff I’m messing about with at the moment—don’t know if it is of any help

4
eoliphant01:08:35

Will check it out

abdullahibra13:08:04

what i would like to do is view list of cards, and when press card i make another action of pressing card

abdullahibra13:08:19

and change it's class

lilactown14:08:29

@abdullahibra unfortunately that is going to re-run your for ... form everytime it re-renders, which means it’s going to create a new class atom that is the initial value when it goes to re-render the old updated atom

lilactown14:08:27

to kind of match the way you’ve written it here:

(let [class-atom (reagent/atom {})]
  ;; initialize state
  (doseq [h all-things]
    (swap! class-atom assoc (:id h) "class1"))

  ;; return a function to be run every re-render
  (fn []
    (for [h all-things]
      [:div {:class "foo" :id (:id h)}
       :on-click #(swap! class-atom assoc (:id h) "class2")
       [:div {:class (@class-atom (:id h))}]])))