Created
March 19, 2023 12:57
-
-
Save avidrucker/750d9a4f2d2fc95a3015dd5c3962f930 to your computer and use it in GitHub Desktop.
Tiny Counter in Reagent & ClojureScript for Klipse
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
;; this code will work in Klipse if and only if the URL is http://app.klipse.tech/?container=1 | |
(require | |
'[reagent.core :as r] | |
'[reagent.dom :as r-dom]) | |
;; TODO: refactor app to hold & manage its own state as a form-3 component | |
(def counter (r/atom 0)) | |
(defn app [] | |
[:main | |
[:h1 | |
{:style {:margin "0"}} ;; no h1 margins | |
"Tiny Counter"] | |
[:div | |
{:style {:padding "0.5em 0"}} ;; vertical padding | |
"Count: " @counter] | |
[:button | |
{:on-click #(swap! counter inc)} | |
"Increment"]]) | |
;; (r-dom/render [app] (js/document.getElementById "app")) | |
(r-dom/render [app] js/klipse-container) ;; renders the app in Klipse | |
(app) ;; displays hiccup in Klipse "stdout" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment