Skip to content

Instantly share code, notes, and snippets.

@seancorfield
Last active December 26, 2016 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seancorfield/8f62615233244820c8db to your computer and use it in GitHub Desktop.
Save seancorfield/8f62615233244820c8db to your computer and use it in GitHub Desktop.
(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