This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-05
Channels
- # architecture (23)
- # bangalore-clj (2)
- # beginners (93)
- # cider (27)
- # cljsjs (2)
- # clojure (66)
- # clojure-russia (9)
- # clojure-spec (28)
- # clojure-uk (3)
- # clojurescript (47)
- # cursive (2)
- # data-science (2)
- # datomic (10)
- # editors (9)
- # emacs (4)
- # figwheel (3)
- # figwheel-main (1)
- # hyperfiddle (2)
- # jobs (1)
- # nrepl (59)
- # off-topic (2)
- # onyx (10)
- # pedestal (1)
- # re-frame (13)
- # reagent (9)
- # reitit (17)
- # shadow-cljs (8)
- # tools-deps (4)
- # vim (2)
@eoliphant This is from the stuff I’m messing about with at the moment—don’t know if it is of any help
hi guys
what i would like to do is view list of cards, and when press card i make another action of pressing card
and change it's class
@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
what you’ll want to do is use what’s called a “form-2” component: https://github.com/reagent-project/reagent/blob/master/doc/CreatingReagentComponents.md#form-2--a-function-returning-a-function
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))}]])))