react

"mulling over state management stuff"
lilactown 2020-05-28T18:15:23.253600Z

would anyone be willing to give some feedback on a blog post I’ve written?

👍 1
lilactown 2020-05-28T18:15:25.253800Z

https://lilac.town/writing/hooks-and-atoms/

lilactown 2020-05-28T18:15:49.254400Z

it’s an attempt to explain the differences between react hooks and reagent atoms

orestis 2020-05-30T13:05:44.286800Z

I like it! It actually helped to clear my mind on some things (storing the state in the immutable render tree e.g.)

orestis 2020-05-30T13:08:33.288900Z

I would show the equivalence between class components and stateful function components, seems like a lot of CLJS people are not up to date with hooks.

orestis 2020-05-30T13:10:27.290800Z

And finally the useMutableSource API which allows React to sync with an external mutable source which avoids tearing. I suspect Redux E.g. will adopt that.

lilactown 2020-05-30T18:38:47.294200Z

i think that the key understand tho is that all useMutableSource does is help React realize that the state has drifted and restart rendering

lilactown 2020-05-30T18:53:50.300Z

so it’s not for free

orestis 2020-05-30T19:00:55.300800Z

In newer versions they will improve perf a little bit (lanes)

orestis 2020-05-30T19:01:05.301400Z

I’m basing this on browsing PRs

lilactown 2020-05-30T19:04:05.305400Z

yeah hopefully. I haven’t grokked the new “lanes” concept yet

orestis 2020-05-30T19:04:07.305700Z

It’s not for free - but global state is unavoidable in most applications. For many use cases performance is irrelevant because the state changes “rarely”, E.g. fetching from an API

lilactown 2020-05-30T19:04:46.308400Z

yep data fetching, navigation, etc. are major reasons for needing external state

orestis 2020-05-30T19:05:06.309100Z

I decided to throw in the towel with trying to read the tea leaves of the React team. I think having an API of a custom hook can let me build for today and be able to be nimble tomorrow.

lilactown 2020-05-30T19:05:41.310700Z

yep yep! I just hide all my stuff behind a custom hook and wait to see what works best :D

orestis 2020-05-30T19:05:45.310900Z

Recoil E.g. has an interesting idea. The state identifiers are global but state is stored in the React tree.

orestis 2020-05-30T19:06:07.311800Z

I can definitely make reseda work like that eventually.

lilactown 2020-05-30T19:06:11.312100Z

yeah, I’m interested to see how successful it is

lilactown 2020-05-30T19:06:25.312700Z

I had a similar idea but I was wary of the performance of that much indirection

lilactown 2020-05-30T19:06:57.314400Z

also the API is really wonky if you want to use it with things outside of React

orestis 2020-05-30T19:06:59.314700Z

I’m still not sure if just getting references to setState hooks and calling them in a batch makes sense or not.

orestis 2020-05-30T19:07:34.315600Z

I mean, for react stable that’s all you can do, right?

lilactown 2020-05-30T19:09:02.316400Z

it gets real weird because you need to ensure that you don’t call setState on a component that’s been unmounted

lilactown 2020-05-30T19:09:07.316800Z

and other corner cases. it’s icky

orestis 2020-05-30T19:24:09.330200Z

Yeah, I guess - looking at redux and others you just have to useLayoutEffect or something along those lines. But to force a rerender it’s either a HOC or that...

lilactown 2020-05-28T18:19:39.255100Z

pointing out any inconsistencies / incorrect / confusing parts would be useful 🙂

alidlorenzo 2020-05-28T18:37:49.255200Z

reading now and will DM you some feedback

lilactown 2020-05-28T18:38:04.255400Z

🙏 thank you!

alidlorenzo 2020-05-28T18:38:43.255600Z

i just finished up an essay I’m about to post so I know* the feel

aisamu 2020-05-28T18:43:20.256Z

I suspect your reagent component won't work, because it'll get re-rendered and reset the state everytime. It has to return a fn that closes over that state

lilactown 2020-05-28T18:45:40.257100Z

Ah yes I need to correct it to be a form-2! Thanks