我只是在Clojurescript中学习Reagent,我只是关注一些教程,但也许我想念一些我有这个代码的状态
(defonce app-state (atom {:text "Hello Chestnut!" :click-count 0}))
和渲染视图
(defn article []
[:div
[:div "The atom" [:code "click-count"] " has value : " (:click-count @app-state)]
[:input {:type "button" :value "Add"
:on-click #(swap! (:click-count @app-state) inc)}]
]
)
我按下按钮时尝试增加状态,但是我在控制台上出现了这个错误
错误:没有协议方法ISwap.-swap!为类型编号定义:0
答案 0 :(得分:4)
应该交换原子而不是:click-count
(swap! app-state update :click-count inc)