lilactown / helix

A simple, easy to use library for React development in ClojureScript.
Eclipse Public License 2.0
631 stars 52 forks source link

Sanity check on using hx for hiccup from helix #34

Closed aiba closed 4 years ago

aiba commented 4 years ago

I couldn't get either sablono or hicada to work with React Native elements, and I always had good success with hx, so I've been using this defnc macro:

(defmacro defnc [type params & body]
  (let [default-opts {:helix/features {:fast-refresh true}}
        [opts body] (if (map? (first body))
                      [(first body) (rest body)]
                      [{} body])]
    `(helix.core/defnc ~type ~params
       ~(merge default-opts opts)
       (hx.react/f (do ~@body)))))

Just wanted a sanity check that hx.react/f is the right way to wrap hiccup bodies.

I could also create a PR adding a note to docs/react-native that this seems to be the best way to get hiccup working for helix + react-native.

lilactown commented 4 years ago

yeah, using hx/f is the best way!

I think it will be difficult to use sablono and hicada in a custom defnc macro since they try and parse at compile time, which means it needs to inspect all of the lets that are often used in helix component bodies. Using their html macros explicitly in each component is probably the best option for now.

Libraries that do fast runtime interpretation (hx, reagent) can easily be wrapped in a custom macro like you have here!