Fork me on GitHub
#reagent
<
2020-12-02
>
lilactown01:12:32

Yes. Reagent has its own scheduler for updates from reagent atoms. By default, updates are asynchronous. Flush synchronously updates the component

jaime12:12:00

Got it! thank you for answering 😄

theeternalpulse02:12:43

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

Lu12:12:20

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?

p-himik12:12:44

What's unsafe about just swapping a ratom?

p-himik12:12:59

Assuming you won't get into an infinite loop.

Lu13:12:29

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

Lu13:12:55

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

Lu13:12:28

The effect hook would work perfectly fine for this, but that means rewriting so much code and can’t do that

p-himik13:12:45

Triggering a state update when a component re-renders can create an infinite loop regardless of how you update the state.

p-himik13:12:26

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.

p-himik13:12:38

Alternatively, you can use the relevant lifecycle method: https://reactjs.org/docs/react-component.html#componentdidupdate

p-himik13:12:46

Note that it's not called on the very first render.

Lu13:12:57

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:

emil0r13:12:14

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?

p-himik13:12:49

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

3