This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-03
Channels
- # aleph (1)
- # announcements (3)
- # aws (36)
- # babashka (35)
- # beginners (25)
- # cider (14)
- # clj-kondo (3)
- # clojure (154)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-serbia (1)
- # clojure-uk (133)
- # clojurescript (36)
- # cursive (15)
- # data-science (7)
- # datomic (16)
- # fulcro (34)
- # immutant (9)
- # jackdaw (5)
- # jobs (1)
- # leiningen (39)
- # off-topic (25)
- # pathom (42)
- # planck (13)
- # play-clj (1)
- # re-frame (18)
- # reagent (6)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (16)
- # shadow-cljs (67)
- # sql (22)
- # testing (1)
- # uncomplicate (2)
- # vim (21)
- # vscode (6)
When writing simple custom components, is there an idiomatic way of having its params map be optional?
Such that that both [my-widget [:span "hi"]]
and [my-widget {:class "thing"} [:span "hi"]]
would be acceptable.
I'm currently implementing such components using a util function, eg.:
(defn my-widget
[& args]
(let [[params & content] (utils/args->params-content args)
params (assoc params :blah "blah")]
[:div params content]))
But I feel like there's something clever/basic I'm missing? Or is it simply more idiomatic to just require an explicit params map, even if it's empty?Hmm, good suggestion! IIUC:
(defn my-widget
[& _]
(let [props (reagent/props (reagent/current-component))
children (reagent/children (reagent/current-component))]
[:div props children]))
Looks a bit nicer, but sidestepping the function's explicit args feels maybe a bit too magical. 😕