Last active
December 26, 2016 09:45
-
-
Save seancorfield/8f62615233244820c8db 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
(ns example | |
(:require [reagent.core :as r :refer [atom]] | |
[reagent.cursor :as c])) | |
(defn input [prompt val] | |
[:div | |
prompt | |
[:input {:value @val | |
:on-change #(reset! val (.-target.value %))}]]) | |
(defn name-edit [n] | |
(let [{:keys [first-name last-name]} @n] | |
[:div | |
[:p "I'm editing " first-name " " last-name "."] | |
[input "First name: " (c/cursor [:first-name] n)] | |
[input "Last name: " (c/cursor [:lastname] n)]])) | |
(defonce person (atom {:name | |
{:first-name "John" :last-name "Smith"}})) | |
(defn parent [] | |
[:div | |
[:p "Current state: " (pr-str @person)] | |
[name-edit (c/cursor [:name] person)]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment