I am trying to understand how input fields work in Reagent.
I first tried to bind on-change
to a simple function that changes underlying atom:
(defonce app-state
(reagent/atom "Teodor"))
(defn page [ratom]
[:div
[:p
"Please enter your name: "
[:input {:on-change #(swap! ratom %)
:value @ratom}]]
[:p "Your name is " @ratom]])
... which did not work. This, however, does:
(defonce app-state
(reagent/atom "Teodor"))
(defn page [ratom]
[:div
[:p
"Please enter your name: "
[:input {;:on-change #(swap! ratom %)
:on-change (fn [evt]
(reset! ratom (-> evt .-target .-value)))
:value @ratom}]]
[:p "Your name is " @ratom]])
I've managed to desugar the ->
macro:
(fn [evt]
(reset! ratom (-> evt .-target .-value)))
;; is the same as
(fn [evt]
(reset!
ratom
(.-value (.-target evt))))
- What do
.-value
and.-target
do? - Where can I find documentation for
.-value
and.-target
? - Why choose the more complicated semantics?