Closed bglgwyng closed 1 year ago
I've thought of it more and just realize the very simple fact that we can just modify the implementation of useRestore
also!
So Please consider HydrationGuard
proposal being parallel to useRestore
.
moved to react-relay-offline https://github.com/morrys/react-relay-offline/issues/33#issuecomment-1649649175
Throughout the day, I have been troubleshooting a perplexing issue with the branching logic of 'react-relay-offline', specifically with the online/offline behavior. Finally, I identified that the problem lies with the
useRestore
function.Please see the following code.
I think this is a quite common pattern to initialize
environment
usinguseMemo
to support multiple users. However,useRestore
is not designed to support this pattern.useRestore
usesuseState
internally to keep the state of hydration, so that it doesn't rehydrate the new environment whenuserId
ortoken
is changed. First I tried to modifyuseRestore
to throw suspense when it's not rehydrated. But it requires an external store like 'recoil' to keep the state of rehydration. And it's not a good idea to add another dependency toreact-relay-offline
to solve this small problem.So my current solution in my project looks like this.
And this is how to use
HydrationGuard
I'm quite satisfied with this solution and think supporting
HydrationGuard
inreact-relay-offline
is a good idea. What do you guys think? I'm happy to make a PR if you guys think it's a good idea.