reagent

Mateusz Mazurczak 2023-05-20T10:40:35.657489Z

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
souenzzo 2023-08-09T14:27:28.028989Z

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

Mateusz Mazurczak 2023-05-20T10:43:17.947679Z

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

Sam Ritchie 2023-05-20T13:46:31.777319Z

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

Mateusz Mazurczak 2023-05-21T00:13:09.318109Z

yeah [:f> simple2]