Created
August 31, 2016 13:52
-
-
Save jwdevantier/ac5327da02f6730cde832a385d51f4a2 to your computer and use it in GitHub Desktop.
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
(defn greet-number | |
"I say hello to an integer" | |
[num] ;; an integer | |
[:div (str "Hello #" num)]) ;; [:div "Hello #1"] | |
(defn more-button | |
"I'm a button labelled 'More' which increments counter when clicked" | |
[counter] ;; a ratom | |
[:div {:class "button-class" | |
:on-click #(swap! counter inc)} ;; increment the int value in counter | |
"More"]) | |
(defn parent | |
[] | |
(let [counter (reagent.ratom/atom 1)] ;; the render closes over this state | |
(fn parent-renderer | |
[] | |
[:div | |
[more-button counter] ;; no @ on counter | |
[greet-number @counter]]))) ;; notice the @. The prop is an int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment