react

"mulling over state management stuff"
orestis 2020-09-09T14:02:58.000700Z

So for the last few weeks, we have been using Reseda in anger. It’s actually quite nice 😄 Clojure atoms for the win.

orestis 2020-09-09T14:03:20.001200Z

I’m hoping to find some time to writer a proper README and announce it.

👏 2
dominicm 2020-09-09T17:10:45.001400Z

That's great :D

dominicm 2020-09-09T17:11:21.001600Z

I learned something surprising recently, I've been meaning to mention it here, because I feel like I might be wrong. set-xxx from useState isn't transactional! It causes an immediate re-render before continuing onto further statements

dominicm 2020-09-09T17:11:50.001700Z

We were getting errors from impossible states because we had functions calling (set-xxx 10) (set-yyy 20)

lilactown 2020-09-09T17:16:18.002200Z

hmm yeah, I think there’s a version of React where batching is enabled. or you can maybe enable it now?

dominicm 2020-09-09T17:17:17.002800Z

Oh, you have to globally enable it? Interesting that it's like that.

orestis 2020-09-09T17:18:31.003400Z

That sounds wrong to me @dominicm

orestis 2020-09-09T17:18:55.004300Z

Inside event handlers state changes are batched

dominicm 2020-09-09T17:19:27.006100Z

I didn't believe it either, but it was happening. I added logs to the render to prove that it was changing between the set state calls.

lilactown 2020-09-09T17:19:32.006400Z

> “Currently (React 16 and earlier), only updates inside React event handlers are batched by default” , according to https://stackoverflow.com/questions/48563650/does-react-keep-the-order-for-state-updates/48610973#48610973.

orestis 2020-09-09T17:19:34.006600Z

For doing manual batching there’s an unsafe prefixed function you can call.

dominicm 2020-09-09T17:19:58.007200Z

Ah. We maybe weren't in a react event handler.

orestis 2020-09-09T17:20:16.007600Z

Logging inside renders is also unsafe :)

orestis 2020-09-09T17:21:14.009200Z

Try tap or something that doesn’t use console.log and you’ll see double renders.

lilactown 2020-09-09T17:22:05.009400Z

yeah that’s so silly they did that

dominicm 2020-09-09T17:22:10.009700Z

Wait, what

lilactown 2020-09-09T17:22:21.010200Z

I think that’s only in CM

lilactown 2020-09-09T17:23:14.011100Z

in concurrent mode + dev bundle, React will render your component twice to force you to make your code concurrent-mode safe

lilactown 2020-09-09T17:23:35.011800Z

during the second render, they actually monkey patch console.log to avoid logging things twice 😵

lilactown 2020-09-09T17:23:56.012300Z

which IMO makes CM bugs that much harder to catch

dominicm 2020-09-09T17:25:02.012700Z

No no no no no 😢

orestis 2020-09-09T18:32:36.013200Z

OK, I have a first round of docs in: https://github.com/orestis/reseda — any kind people that would do a proofread?

lilactown 2020-09-10T15:54:06.014400Z

I like this a lot. looks simple and the README examples are illustrative

orestis 2020-09-10T17:04:11.016Z

It’s super simple. The useStore is mainly copied from the use-subscription package and made a bit more Clojurey. The useSuspending is hairy but seems to work fine.

orestis 2020-09-10T17:04:33.016800Z

There’s no more promises or callbacks in our UI code. It’s super nice.

orestis 2020-09-09T18:33:22.013500Z

I’m actually heading to bed 😄

dominicm 2020-09-09T19:24:35.013900Z

Looks ok to me, cursory read though