Fork me on GitHub
#reagent
<
2024-06-03
>
Joshua Shevach13:06:45

Do props count as reactive values for r/reaction and r/track?

p-himik13:06:04

No, unless the values in those props are themselves reactive. But you can also come up with a situation where it might seem as if they're reactive. Something like:

(def counts (r/atom []))

(defn total-view-impl [total']
  [:span "Total: " @total'])

(defn total-view [offset]
  (let [total (r/reaction (+ offset (apply + @counts))]
    [view-impl total]))
But of course it is only an illusion because that reaction will be re-created anew each time the offset changes. It would not be recreated if [view-impl total] was wrapped in another fn, and it would not track any changes to offset.

Joshua Shevach13:06:26

Hmmm so ideally we'd be looking at a form 2 that captures the prop in a reactive store and then uses that in the render fn?

p-himik13:06:48

In general, you don't need to capture anything, unless some underlying component expects a reaction. You can just use the prop value as is. There's also r/with-let that, I think, deals with that.