Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork22
Is context provider in SSR mode necessary?#87
-
Since pullstate implements an alternative to the context API, is there a way to avoid using it in SSR? |
BetaWas this translation helpful?Give feedback.
All reactions
If you are manipulating the state during the rendering on the server-side and need to hydrate that state on the client side (which is generally always the case) - then there is no other way to go about it than using context.
Any library which does SSR and is manipulated during a render needs to have context- there's no way around it, because each separate user "request" on a server needs to maintain a unique state, which can't be controlled globally like we do on the client (otherwise all requests share the same state and clash / overwrite each other)- hence context is required.
If you are not manipulating the state during rendering on the server, then you don't need the context provider.…
Replies: 1 comment 2 replies
-
If you are manipulating the state during the rendering on the server-side and need to hydrate that state on the client side (which is generally always the case) - then there is no other way to go about it than using context. Any library which does SSR and is manipulated during a render needs to have context- there's no way around it, because each separate user "request" on a server needs to maintain a unique state, which can't be controlled globally like we do on the client (otherwise all requests share the same state and clash / overwrite each other)- hence context is required. If you are not manipulating the state during rendering on the server, then you don't need the context provider. But I'd recommend just putting it in anyway because you might run into weird issues in the future. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
For the sake of discussion, is it possible to implement Something along the lines of: // redactedEdit: Nvm, I just answered my own question. It would in fact lead to very ugly code. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I feel you, I also had a big aversion to it- and tried my hardest to not have to use it with Pullstate. But when it comes down to it, and after much testing and thought, it just isn't something that can be done- conceptually, React needs a way to hold state during render on the server- which we pass on to the client- and context is what provides that. I've come to understand the need for it and I don't dislike it as much as I used to though. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1