Skip to content

Instantly share code, notes, and snippets.

@thheller
Created August 24, 2017 13:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thheller/7f530b34de1c44589f4e0671e1ef7533 to your computer and use it in GitHub Desktop.
Save thheller/7f530b34de1c44589f4e0671e1ef7533 to your computer and use it in GitHub Desktop.
class extends React.Component in CLJS
(defn my-component [props context updater]
(cljs.core/this-as this
(js/React.Component.call this props context updater)
;; anything else you want to set-up. use goog.object/set on this
this))
(gobj/extend
(.. my-component -prototype)
js/React.Component.prototype)
;; cljs-specific properties on constructor
;; just so (prn my-component) works properly, not actually required
(set! (.-cljs$lang$type my-component) true)
(set! (.-cljs$lang$ctorStr my-component) "MyComponent")
(set! (.-cljs$lang$ctorPrWriter my-component)
(fn [this writer opt]
(cljs.core/-write writer "MyComponent")))
(set! (.. component-fn -prototype -constructor) my-component)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment