Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

re-frame: reset atom after dispatch

I have this form:

(defn input-question
  []
 (let [new-question (reagent/atom "")]
  (fn []
  [:div
   [:input {:type      "text"
            :value     @new-question
            :on-change #(reset! new-question (-> % .-target .-value))}]
   [:input {:type     "button"
            :value    "Save new question"
            :on-click #(re-frame.core/dispatch [:create-question @new-question])} ] ])))

How can I reset @new-question to "" (empty string) after the dispatch?

like image 831
aarkerio Avatar asked Aug 24 '26 13:08

aarkerio


1 Answers

You can use reset! on the ratom after dispatching:

#(do (re-frame.core/dispatch [:create-question @new-question])
     (reset! new-question ""))

to reset it after dispatching the value.

like image 66
Daniel Compton Avatar answered Aug 27 '26 04:08

Daniel Compton