Re:Recoil – A state management library for React
by davidmccabe on Thursday May 14, 2020 @05:07PM
(#23185451)
It’s actually designed to make server rendering easy. We’ll add a guide about this eventually. Atoms aren't global singletons: their values are scoped to React trees.
[ Parent
| on HN ]
Re:Recoil – A state management library for React
by mleonard on Friday May 15, 2020 @04:51AM
(#23190183)
Can you talk about SSR here just a little to give us an idea of how recoil makes it easy?
Re:Recoil – A state management library for React
by davidmccabe on Friday May 15, 2020 @02:10PM
(#23195368)
Well, I should say "doesn't make it harder". The `RecoilRoot` component accepts a prop called `initializeState` that lets you specify the state of all atoms in the initial render.
Shouldn't the app be allowed to "pull" the required state from the db, rather than having to "push" the initial state into the root of the app? It's not like we should dump the whole database into atoms just in case the app needs to look up one item, right?
I'm mostly curious how this might tie into a server-side DB. Recoil's API provides the fundamentals for a firebase-like persistence system that allows people to skip the complexity of GraphQL, and just use the type system provided by the language (flow/ts/reason).
In any case, congrats on launching such an elegant API. This is one of the nicest reactive systems I've seen for React :-D
Re:Recoil – A state management library for React
by davidmccabe on Monday May 18, 2020 @11:48PM
(#23231119)
We are planning in the next few weeks an overhauled persistence API. Among other things this will add the ability to provide a callback in `initializeState` rather than a value. However, this doesn't help if you need to do async work to retrieve the value. The way we generally think of SSR is that you get a single render pass and then you're done, no time for async work. So for hitting a database you want something like Relay that statically knows your data dependencies and can do a single request to initialize. It's true that there's some complexity there, but there are also great solutions to really hard problems. Recoil doesn't attempt to address that space.