Fork me on GitHub
#helix
<
2021-08-31
>
danielneal06:08:46

ah cool. So just hooks and local state

danielneal06:08:49

I can do that

danielneal06:08:09

do you pass callback functions into components

danielneal06:08:20

or use a context

danielneal06:08:11

I guess local state composes better anyway

lilactown15:08:53

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

🎯 4
lilactown15:08:51

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")))))