Skip to content

Instantly share code, notes, and snippets.

@jwdevantier
Created August 31, 2016 13:52
Show Gist options
  • Save jwdevantier/ac5327da02f6730cde832a385d51f4a2 to your computer and use it in GitHub Desktop.
Save jwdevantier/ac5327da02f6730cde832a385d51f4a2 to your computer and use it in GitHub Desktop.
(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