Fork me on GitHub

I was wondering, in plain React you can have the problem that setState is called in a promise, and that the component is already unmounted while the promise is still running. Then you get the error: “Trying to call setState on an unmounted component.” Why have I never seen this error in Reagent? 🙂


@erwinrooijakkers it’s certainly possible to make that mistake in reagent, but I think with idiomatic reagent you would never use react’s state mechanism: instead you’d just to reagent’s atom mechanism. if you update an atom after an unmount, it won’t cause an error: the atom will get updated but there just won’t be a watcher on it


And in React we have to use this state management mechanism? It doesn’t have something like Reagent atoms?


you don’t have to use react state. many people use an external library like redux or react saga to implement the so called “flux” one-way dataflow. or something like mobx. mobx is probably most similar to the reagent ratom technique. they both basically implement an observer pattern


but nothing is as solid as reagent’s atoms because it isn’t possible to fully proxy javascript arrays in the current language, so you have to be very careful to code to a convention with mobx


Thanks clear. Yes redux is used, but setState as well


right. i guess the most straightforward answer is that if you need setState in react, the idomatic way of doing that in reagent is with a form-2 component and a locally declared ratom


Yeah which is much less to worry about


somewhere i read (probably on twitter) that the setState interface was a design concession and meant as something transitional. the react people really wanted a declarative immutable style because the problem they were trying to solve was actually code correctness (not speed)

Umar Daraz18:04:29

Hi Everybody Is it possible to use render props pattern with reagent?


it works exactly like in javascript

Umar Daraz18:04:39

Thanks I m able to make it work with render prop. Some how it was not working with children prop May be I m missing something


well, keep in mind that reagent has a funny way of distinguishing between children and props. if the first argument to the component function is a map, then that is treated as the “props”. all other arguments are just children.


but you can pass functions wherever

Umar Daraz19:04:37

I did not know that before Will keep this in mind Thanks again for the help 🙂


If i use a ratom inside of a function (instead of directly inside of a component), will it still reactively re-render?



(def store (r/atom {:copy {"123" "some copy"))

(defn get-copy [id]
   (get-in [:copy id] @store))

(defn component [id]
  (let [copy (get-copy id)]
    [:div copy]))


@lilactown it should rerender if you are calling the function from inside the component (like you are). However, I think there is a subtle bug in the get-copy function.. @store and [:copy id] should be switched.


hah! 😅 thanks!!