This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-31
Channels
- # announcements (3)
- # aws-lambda (1)
- # babashka (122)
- # beginners (241)
- # calva (28)
- # cider (7)
- # clara (7)
- # clj-kondo (43)
- # clojars (5)
- # clojure (326)
- # clojure-europe (60)
- # clojure-italy (2)
- # clojure-nl (4)
- # clojure-spec (21)
- # clojure-uk (4)
- # clojurescript (162)
- # cursive (30)
- # datomic (3)
- # editors (5)
- # emacs (4)
- # figwheel-main (1)
- # fulcro (24)
- # gratitude (3)
- # helix (7)
- # honeysql (20)
- # improve-getting-started (1)
- # introduce-yourself (11)
- # jobs (3)
- # joker (2)
- # kaocha (15)
- # lsp (21)
- # lumo (2)
- # meander (3)
- # off-topic (34)
- # re-frame (6)
- # reagent (1)
- # releases (4)
- # rum (2)
- # shadow-cljs (37)
- # spacemacs (16)
- # tools-deps (16)
- # vim (23)
- # xtdb (32)
ah cool. So just hooks and local state
I can do that
do you pass callback functions into components
or use a context
I guess local state composes better anyway
I try to design my components so they take just data and callbacks. I only use context for very specific global things like navigation, or theming, and even then I typically hide that behind a custom hook like use-navigation
and use-theme
but that's only for concerns I use everywhere. for instance, if I had a modal component, instead of looking up the current modal content in a global atom and dispatching a global modal-close
handler, I would take all of that information as props. The only thing I would look up in a global context would be a theme, hidden behind a use-theme
hook
(defnc modal
[{:keys [class children on-close]}]
(let [{:keys [border-primary bg-primary text-primary]}] (use-theme)]
(d/div
{:class (flatten ["floating" border-primary bg-primary text-primary class])}
(d/div children)
(d/div
{:class "right-align"}
(d/button {:on-click on-close} "Close")))))