Fork me on GitHub
#clojurescript
<
2024-02-09
>
Danny Hull19:02:47

Why do we need an r/atom when a Reagent component, to my understanding, only changes when its internal state and/or props are different than before?

dpsutton19:02:39

r/atom is the mechanism by which a reagent component changes when that state changes

Danny Hull19:02:32

So if we use a plain old Clojure atom, it wouldn't count as a state change?

dpsutton19:02:40

it’s state that would change. But the react component wouldn’t care. same as if you printed to the console. state has changed, but who cares

Danny Hull19:02:04

So just to confirm further, if the regular Clojure atom was 0 and we keep incrementing it, it wouldn't change a thing (assuming props don't change in the component)

Danny Hull19:02:39

So r/atom is basically a plain old Clojure atom with an event listener for the state change and the callback being to render the component again

dpsutton19:02:58

yup. just component aware and tells it to rerender