Skip to content

Instantly share code, notes, and snippets.

@avidrucker
Created March 19, 2023 12:57
Show Gist options
  • Save avidrucker/750d9a4f2d2fc95a3015dd5c3962f930 to your computer and use it in GitHub Desktop.
Save avidrucker/750d9a4f2d2fc95a3015dd5c3962f930 to your computer and use it in GitHub Desktop.
Tiny Counter in Reagent & ClojureScript for Klipse
;; 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