How do I include/inject a prop into helix
component?
what do you mean?
probably &
If I have a prop that I don´t want to include in all my components like ($ Comp {:inject value} children)
I thought do something like this:
(ns app.lib
#?(:clj (:require [helix.core :as helix]))
#?(:cljs (:require-macros [app.lib])))
#?(:clj
(defmacro defnc [type params & body]
(let [opts? (map? (first body)) ;; whether an opts map was passed in
opts (if opts?
(first body)
{})
body (if opts?
(rest body)
body)
;; feature flags to enable by default
default-opts {:helix/features {:fast-refresh true}}]
`(helix.core/defnc ~type ~params
;; we use `merge` here to allow indidivual consumers to override feature
;; flags in special cases
~(merge default-opts opts)
~@body))))
like in default-opts
, is that right?
in all of your components?
yes
does the value
change?
no
or maybe
I would use React context for this
and when you need the value, you can use use-context
to get it
(def value-context (helix/create-context "some value"))
then in your components:
(defnc my-component [props]
(let [value (hooks/use-context value-context)]
,,,))
Understand, thanks
so, you shoud use use-context
too, 🙂 just kidding