reagent 2023-05-20

Hi, in reagent for the local state is it better to use a reagent atom or state hooks? Example: r/atom

(defn simple []
  (let [simple-v (r/atom 0)]
    (fn []
      [:div
       [:div @simple-v]
       [:button {:onClick #(swap! simple-v inc)} "Inc!"]])))
State Hook
(defn simple-2 []
  (let [[simple-v set-simple-v] (react/useState 0)]
    [:div
     [:div simple-v]
     [:button {:onClick #(set-simple-v inc)} "Inc!"]]))
What's your preference?

⚛️ 1

actually https://reagent-project.github.io/docs/master/reagent.core.html#var-with-let

(defn simple
  []
  (r/with-let [*simple-v (r/atom 0)]
    [:div
     [:div @*simple-v]
     [:button {:onClick #(swap! *simple-v inc)} "Inc!"]]))
use react/useState with [:div components I think that is wrong. I would be surprised if it works

I've always used r/atom but started wondering about useState today

In the second example you’d have to use simple-2 with :f> right?

yeah [:f> simple2]