Next.js Discord

Discord Forum

Conditional SSR context, unified interface?

Unanswered
Devon Rex posted this in #help-forum
Open in Discord
Devon RexOP
Is it possible in NextJS to conditional render either context A or B from the server, and have hooks that dispatch the correct logic underneath such that hook set C adapts to either underlying context?

3 Replies

Black carp
No. If you dynamically render a context provider, executing a hook that depends on it will result in an exception being thrown.

That being said, you could have fallback values for contexts A and B, so that you know if either was defined (A.k.a. their value is on the fallback one). Then in your hooks you could check under which scenario you currently are and act accordingly.
Thanks for the answer!