This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-28
Channels
- # announcements (2)
- # babashka (16)
- # bangalore-clj (1)
- # beginners (93)
- # boot (11)
- # calva (5)
- # cider (13)
- # clj-kondo (49)
- # cljdoc (14)
- # cljs-dev (1)
- # clojure (99)
- # clojure-dev (3)
- # clojure-europe (1)
- # clojure-india (1)
- # clojure-italy (9)
- # clojure-nl (3)
- # clojure-poland (1)
- # clojure-russia (1)
- # clojure-spec (31)
- # clojure-uk (21)
- # clojured (2)
- # clojurescript (18)
- # core-async (12)
- # cursive (36)
- # data-science (1)
- # datomic (54)
- # duct (3)
- # emacs (33)
- # events (1)
- # fulcro (17)
- # jobs (1)
- # joker (8)
- # keechma (1)
- # leiningen (7)
- # malli (8)
- # nrepl (19)
- # pathom (6)
- # planck (18)
- # re-frame (20)
- # reagent (18)
- # shadow-cljs (3)
- # sql (7)
- # vim (31)
Why not using the component directly with :>
. Similar to material-ui
How would that look?
When defining Form 2 components should the outer and render function always take the same number of args? Or is there a valid use case for diverging from this pattern?
they effectively take the same arguments, but you might ignore some in initial render vs. subsequent renders so you can be lazy and leave them out
e.g.:
(defn my-component [styles initialization-data]
(let [subscription (subscribe-with-initialization initialization-data)]j
(fn [styles] ;; <-- we leave out initialization-data because we don't use it on subsequent renders
[:div (prn @subsription)])))
Yeah, I know the general advice is to match arity, wondered if people had experience where they had good reason not to follow this.
I guess if you wanted access to the initial value only (not sure the use case there though)
Funny you should link said example, I just felt the pain of this approach. To the consumer it's not clear when invoking the component which args will only be used on init.
Is there any benefit over this vs still including it but with a _ as the binding?
Maybe unnecessary render calls if init-data changes a lot.
the returned fn will be called whenever init-data
changes whether or not it is included in the arguments
I also have a personal rule that I always accept a single map of arguments (a la raw React) instead of taking an ever increasing number of order-reliant arguments, but I understand that I can’t force that on everyone
^ Great advice - I started transitioning all my view components to follow that pattern and it’s simplified quite a bit
:thumbsup: