reagent

A minimalistic ClojureScript interface to React.js http://reagent-project.github.io/
lilactown 2020-12-02T01:48:32.313100Z

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

jaime 2020-12-03T12:32:00.335500Z

Got it! thank you for answering 😄

theeternalpulse 2020-12-02T02:06:43.316400Z

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

theeternalpulse 2020-12-02T02:19:31.316600Z

seems a lot of solutions in this thread https://github.com/reagent-project/reagent/issues/330

Lu 2020-12-02T12:27:20.317900Z

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-himik 2020-12-02T12:38:44.318Z

What's unsafe about just swapping a ratom?

p-himik 2020-12-02T12:38:59.318200Z

Assuming you won't get into an infinite loop.

Lu 2020-12-02T13:04:29.320200Z

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

Lu 2020-12-02T13:06:55.324300Z

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

Lu 2020-12-02T13:07:28.325800Z

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

p-himik 2020-12-02T13:07:45.326200Z

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

p-himik 2020-12-02T13:08:26.327200Z

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.

emil0r 2020-12-02T13:09:14.328300Z

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-himik 2020-12-02T13:09:38.328500Z

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

p-himik 2020-12-02T13:09:46.328800Z

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

Lu 2020-12-02T13:10:57.330100Z

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:

p-himik 2020-12-02T13:21:49.331Z

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

1