Fork me on GitHub
#reagent
<
2018-06-29
>
mhuebert15:06:17

for anyone wanting to use React contexts with Reagent, I wrote a little wrapper this afternoon: https://gist.github.com/mhuebert/d400701f7eddbc4fffa811c70178a8c1 example usage:

(:require [example.reagent-context :as c])

;; in a component somewhere
[c/provide {:app-theme {:color "blue"}}
 [c/consume :app-theme
  (fn [theme]
    [:div
      {:style {:color (:color theme)}} "Colorful Text"])]]
contexts can either be keywords or, if you’re interop’ing with libs, an existing React context instance. Reactivity (with ratoms/reactions) should ‘just work’ even inside the consume callback. (Feedback welcome.)

👍 4
pesterhazy17:06:48

@mhuebert looks very useful

pesterhazy17:06:32

Candidate for inclusion in Reagent IMO

👍 8
lilactown20:06:52

I wrote and released a small library that does similar https://github.com/Lokeh/reagent-context

👍 8
lilactown20:06:04

how does reactivity work within the callback passed to consume?

mhuebert23:06:57

@lilactown 👍:skin-tone-2: I have added a prior art link to your thing in my gist. For reactivity, I used reagent's vector form inside the component to call the function.

mhuebert23:06:57

@lilactown 👍:skin-tone-2: I have added a prior art link to your thing in my gist. For reactivity, I used reagent's vector form inside the component to call the function.