Say that we have a text text area defined in hiccup syntax.
(def written-text (reagent/atom ""))
(defn text-area []
[:textarea
{:value @written-text
:on-change #(reset! written-text (-> % .-target .-value))
:on-click #(println @written-text)}])
Say that we want to have multiple copies of text-area in our document, each with different state in them. Then we'll have to move the state currently available to all in the current namespace into a lexically scoped symbol. Something like:
(defn text-area []
(let [written-text (reagent/atom "")]
[:textarea
{:value @written-text
:on-change #(reset! written-text (-> % .-target .-value))
:on-click #(println @written-text)}]))
But as it stands this code doesn't work. The text field always ends up empty no matter what the user inputs. Why is that? And how do I enclose my state in a per component lexical scope?