Skip to content

Instantly share code, notes, and snippets.

@boogie666
Created April 10, 2019 10:05
Show Gist options
  • Save boogie666/c3eb668dffe6c0bb725b74820ac4d8bc to your computer and use it in GitHub Desktop.
Save boogie666/c3eb668dffe6c0bb725b74820ac4d8bc to your computer and use it in GitHub Desktop.
(defn- -create-react-component
"create a 'inline' component and set the display name to the same name as the function"
[f]
(let [component (fn [js-props]
(let [args (.-uixprops js-props)]
(hiccup->react (apply f args))))]
(set! (.-displayName component) (.-name f))
component))
;; obvious optimization if obvious
(defonce ^:private create-react-component (memoize -create-react-component))
;; compile method for components
(defmethod compile-hiccup-ast :component [[_ {:keys [type args] :as c}]]
(react/createElement (create-react-component type)
#js{:uixprops args}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment