This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-15
Channels
- # announcements (13)
- # beginners (106)
- # cider (70)
- # cljdoc (1)
- # cljsjs (1)
- # clojure (97)
- # clojure-finland (1)
- # clojure-italy (13)
- # clojure-mexico (16)
- # clojure-russia (1)
- # clojure-spec (53)
- # clojure-uk (146)
- # clojurescript (44)
- # core-async (5)
- # cryogen (1)
- # css (1)
- # cursive (11)
- # datomic (89)
- # duct (10)
- # emacs (4)
- # figwheel-main (58)
- # fulcro (5)
- # hispano (35)
- # hyperfiddle (1)
- # jobs (2)
- # jobs-discuss (1)
- # lambdaisland (1)
- # leiningen (3)
- # off-topic (13)
- # onyx (50)
- # parinfer (3)
- # pedestal (4)
- # reagent (9)
- # ring-swagger (56)
- # rum (3)
- # shadow-cljs (85)
- # spacemacs (4)
- # vim (4)
@daviwil thanks man
guys when i define a route with secretary within reagent app, when reload the page i got page not found why?
Hey all, I have seen this pattern, only once, but I wanted to get opinions on it: Example 1
(defn form-3-component
[props]
(let [state (atom {:list [] :contacts []})
on-click! (fn [] (reset! @atom []))])) <--- take note of this
Example 2
(defn delete-list-items
[list-state]
(reset! @list-state []))
(defn form-3-component
[props]
(let [state (atom {:list [] :contacts []})
on-click! delete-list-items] <--- extracted the function from example 1 and brought it outside the component
;; lots of stuff happening
(on-click! (:list @state))))
So the idea is, to extract event-handlers
, or functions that manipulate state, from the container component (form-3) itself. Has anyone seen this pattern used in the wild or think there can be benefits in some situations?
This pattern never really comes up in React applications, but I thought maybe there is some idiom in clojure which makes this make sense?and I think that's mostly fine. you'd actually pass in the whole state atom into delete-list-items
, and I would usually bind the on-click! to the state when you create the atom
(defn delete-list-items
[state]
(swap! state assoc :list []))
(defn form-2-component
[props]
(let [state (atom {:list [] :contacts []})
on-click! #(delete-list-items state)]
;; ...
[:button {:on-click on-click!} "Delete list"]))