Your example does not work because you need to pass a function: click as follows:
[:li [:a {:on-click #(reset! selected-department "test!")} "Dairy"]]
So, the only thing you need to change is to add # before (reset! ...
This is equivalent to
[:li [:a {:on-click (fn [_] (reset! selected-department "test!"))} "Dairy"]]
Edit:
This is the complete code that I tested and works great for me:
(defonce selected-department (atom "department!"))
(defn sidebar []
[:div
[:ul.sidebar-nav
[:li.sidebar-brand [:a {:href "#"} "Departments"]]
[:li [:a {:on-click
[:li [:a {:on-click
[:li [:a {:on-click
[:label @selected-department]])
(reagent/render-component [sidebar] (.getElementById js/document "app"))
The label at the bottom is updated when you click an item in the list.
source
share