would anyone be willing to give some feedback on a blog post I’ve written?
it’s an attempt to explain the differences between react hooks and reagent atoms
I like it! It actually helped to clear my mind on some things (storing the state in the immutable render tree e.g.)
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.
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.
i think that the key understand tho is that all useMutableSource does is help React realize that the state has drifted and restart rendering
so it’s not for free
In newer versions they will improve perf a little bit (lanes)
I’m basing this on browsing PRs
yeah hopefully. I haven’t grokked the new “lanes” concept yet
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
yep data fetching, navigation, etc. are major reasons for needing external state
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.
yep yep! I just hide all my stuff behind a custom hook and wait to see what works best :D
Recoil E.g. has an interesting idea. The state identifiers are global but state is stored in the React tree.
I can definitely make reseda work like that eventually.
yeah, I’m interested to see how successful it is
I had a similar idea but I was wary of the performance of that much indirection
also the API is really wonky if you want to use it with things outside of React
I’m still not sure if just getting references to setState hooks and calling them in a batch makes sense or not.
I mean, for react stable that’s all you can do, right?
it gets real weird because you need to ensure that you don’t call setState on a component that’s been unmounted
and other corner cases. it’s icky
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...
pointing out any inconsistencies / incorrect / confusing parts would be useful 🙂
reading now and will DM you some feedback
🙏 thank you!
i just finished up an essay I’m about to post so I know* the feel
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
Ah yes I need to correct it to be a form-2! Thanks