Created
October 2, 2013 09:25
-
-
Save tonsky/6791188 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn component [ref render-fn & {:keys [on-mount on-unmount]}] | |
(let [comp (React/createClass (clj->js | |
{ :render (fn [] (crate/html (render-fn @ref))) | |
:componentDidMount (or on-mount identity) | |
:componentWillUnmount (or on-unmount identity) }))] | |
(add-watch ref :react | |
(fn [_ _ old new] | |
(when (not= old new) (.forceUpdate comp)))) | |
comp)) | |
(def state (atom {:title "Vasya"})) | |
(component state (fn [val] | |
[:div.class (str "Hello" (:title val))])) | |
(swap! state assoc :title "Petya") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Я только что подумал, что может лучше будет так:
Не очень хорошо, что state надо и создавать, и передавать, но зато он спрятан, и это может макро исправить.