【发布时间】:2019-12-08 07:47:40
【问题描述】:
我正在尝试使用 Reagent 创建 SPA 应用程序。如何定义默认页面/组件?据我了解,我应该将当前页面保存在状态原子中。但是如果我在主页中更改状态,我无法定义它。
例如,在此代码中 home 无法解析(第 1 行):
(defonce app-state (atom {:current-page (home)}))
(defn second-page []
[:p 2])
(defn home []
[:div
[:p 1]
[:input {:type "button" :value "Click!"
:on-click #(swap! app-state second-page)}]])
(defn hello-world []
[:div
[:input {:type "button" :value "Home" :on-click #(swap! app-state home)}]
(:current-page @app-state)
[:h3 "footer"]])
(reagent/render-component [hello-world]
(. js/document (getElementById "app")))
【问题讨论】:
标签: clojurescript reagent