Hello all, any one used use-context
yet?
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
?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)]
...)
inside some-component
or other-component
@fabrao
(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
(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)))
oh, ok, so all the stuffs
will be inside value, thanks
Yeah no problem