helix

https://github.com/Lokeh/helix
fabrao 2020-06-11T18:17:37.241400Z

How do I include/inject a prop into helix component?

lilactown 2020-06-11T18:19:26.241600Z

what do you mean?

Aron 2020-06-11T18:19:46.242Z

probably &

fabrao 2020-06-11T18:21:09.243300Z

If I have a prop that I don´t want to include in all my components like ($ Comp {:inject value} children)

fabrao 2020-06-11T18:22:13.243800Z

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

fabrao 2020-06-11T18:22:31.244200Z

like in default-opts, is that right?

lilactown 2020-06-11T18:29:05.244400Z

in all of your components?

fabrao 2020-06-11T18:29:32.245Z

yes

lilactown 2020-06-11T18:29:33.245100Z

does the value change?

fabrao 2020-06-11T18:29:43.245300Z

no

fabrao 2020-06-11T18:29:50.245500Z

or maybe

lilactown 2020-06-11T18:29:55.245700Z

I would use React context for this

lilactown 2020-06-11T18:30:20.246100Z

and when you need the value, you can use use-context to get it

lilactown 2020-06-11T18:31:20.247400Z

(def value-context (helix/create-context "some value"))
then in your components:
(defnc my-component [props]
  (let [value (hooks/use-context value-context)]
   ,,,))

fabrao 2020-06-11T18:32:08.247800Z

Understand, thanks

fabrao 2020-06-11T18:34:01.248700Z

so, you shoud use use-context too, 🙂 just kidding