Yes. Reagent has its own scheduler for updates from reagent atoms. By default, updates are asynchronous. Flush synchronously updates the component
Got it! thank you for answering 😄
In reagent is there a way to create a context for certain atoms/data sources to be easily accessed without passing them through components. For example I'm using datascript/posh to maintain two states (one for the app and one for the ui specific states) but have to pass them through whenever I need them, sometimes passing down to components that don't use them. In JS react I've used the usecontext, but wondering if there's something similar to that in reagent or a similar strategy equivalent
seems a lot of solutions in this thread https://github.com/reagent-project/reagent/issues/330
I am sure this was already asked at a point.. anyways is there a safe way to trigger a state update when a component re-renders?
What's unsafe about just swapping a ratom?
Assuming you won't get into an infinite loop.
Because I’d end up swapping the atom in the rendered function itself (infinite loop can’t happen in my case). I don’t think it’s a nice thing to do
My problem is I have some local state... My rendering function updates and I was trying to figure out a clean way to update the local state
The effect hook would work perfectly fine for this, but that means rewriting so much code and can’t do that
Triggering a state update when a component re-renders can create an infinite loop regardless of how you update the state.
IMO it is absolutely fine to make non-loop-inducing updates from within the render function if you indeed need to update the state on every render.
Hi. I’m trying to document one of my projects with a bit more style. It’s based on reagent, and I quite liked the reagent project page, where some components are showed and explained along with the source code. The source code is handled by the syntax.clj(s) files in the reagentdemo subproject along with demo-component in common.cljs. Is it OK to copy these and give acknowledgement?
Alternatively, you can use the relevant lifecycle method: https://reactjs.org/docs/react-component.html#componentdidupdate
Note that it's not called on the very first render.
Oh how stupid this is perfect! I was looking at the should update but this is exactly what I needed instead :man-facepalming::skin-tone-3: thanks 🙏:skin-tone-2:
I'm not affiliated with reagent, but its sources' license is MIT, so I'm pretty certain you can do that. https://github.com/reagent-project/reagent/blob/master/LICENSE