helix

lilactown 2021-08-31T15:49:53.032600Z

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

🎯 2
lilactown 2021-08-31T15:54:51.037Z

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

danielneal 2021-08-31T06:57:46.029400Z

ah cool. So just hooks and local state

danielneal 2021-08-31T06:57:49.029500Z

I can do that

danielneal 2021-08-31T06:58:09.030100Z

do you pass callback functions into components

danielneal 2021-08-31T06:58:20.030400Z

or use a context

danielneal 2021-08-31T06:59:11.030700Z

I guess local state composes better anyway