Last active
August 17, 2018 13:14
-
-
Save pesterhazy/39c84224972890665b6bec3addafdf5a to your computer and use it in GitHub Desktop.
React component in pure cljs using ES6 class inheritance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; implementing a React component in pure cljs, no reagent necessary | |
;; using goog.object.extend to create a ES6 class that inherits from | |
;; React.Component | |
;; credit to @thheller | |
(defn MyReact [props context updater] | |
(this-as this | |
(js/React.Component.call this props context updater))) | |
(js/goog.object.extend (.-prototype MyReact) | |
js/React.Component.prototype | |
#js {:render | |
(fn [] | |
(this-as this | |
(js/React.createElement "h1" nil "hello world")))}) | |
(js/ReactDOM.render (js/React.createElement MyReact) js/klipse-container) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just out of curiosity - do you know what the idiomatic way of doing the same with reagent would be?
I currently have imported https://whoisandy.github.io/react-rangeslider via
:foreign-libs
:Then in my
view.cljs
I add this to thens
declaration:[react-rangeslider :as range-slider]
In the hiccup I do the following:
But that spawns an error:
, probably because I need to do what you do above. Which is fine, I'm just not sure what the idiomatic way would be.
Do you happen to know about that?