helix

https://github.com/Lokeh/helix
fabrao 2020-04-07T04:57:05.116200Z

Hello all, any one used use-context yet?

fabrao 2020-04-07T05:36:51.117100Z

I did not understand this

(def my-context (react/createContext "default"))

(helix.core/provider
  {:context my-context
   :value "overrides default value"}
  ($ some-component)
  ($ other-component))
How do I use conext inside some-component?

oconn 2020-04-07T11:10:00.119500Z

There is a good example in the react docs for using context https://reactjs.org/docs/hooks-reference.html#usecontext. Specifically in this case you would call

(let [your-context-value (helix.hook/use-context my-context)] 
  ...)

oconn 2020-04-07T11:10:49.120400Z

inside some-component or other-component @fabrao

fabrao 2020-04-07T12:15:35.121Z

@oconn

(def Contexto (react/createContext))

(defnc Imprimir []
  (let [my (hooks/use-context Contexto)]
    (js/console.log my)
    (d/div
     (d/div (str "Go Message")))))

(defnc App []
  (let [[estado set-estado] (hooks/use-state {:contador 0})]
    (hx/provider
     {:context Contexto
      :estado estado
      :set-estado set-estado}
     ($ Imprimir))))

(defn ^:export start
  []
  (rdom/render ($ App) (js/document.getElementById "app")))
log -> undefined

oconn 2020-04-07T12:37:24.121400Z

(def Contexto (react/createContext {:value 1}))

(defnc Imprimir []
  (let [my-context-state (hooks/use-context Contexto)]
    (js/console.log my-context-state)
    (d/div
     (d/div (str "Go Message")))))

(defnc App2 []
  (provider
   {:context Contexto
    :value {:value 2}} ;; This overrides the initial value
   ($ Imprimir)))

oconn 2020-04-07T12:37:30.121600Z

@fabrao

fabrao 2020-04-07T12:39:27.122400Z

oh, ok, so all the stuffs will be inside value, thanks

oconn 2020-04-07T12:42:27.122700Z

Yeah no problem