What is the proper way to use shared state using createActorContext in NextJS13+ compatible with SSR layouts?
#5185
Unanswered
oleksii-lukin
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
Apologies for the delay - can you make a reproduction (e.g. on StackBlitz) for this? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 have my root layout file that have other providers in it:
I have my Provider component that looks like this:
I made it client component because nextjs was complaining
⨯ TypeError: createContext only works in Client Components.But when I try to add my
FilterMachineContext.Provider, I get these two errors:and
Am I doing something wrong? Is there a fully working example using NextJS somewhere, that uses shared context? I need my filter on products list page, but I also want to use it inside my header component, hence I'm trying to make context global, on top of general layout.
Do I need to include it with some check for server/client sides, like I did for mswjs? It has separate code to handle server and client sides. I took it somewhere from mswjs docs if I recall correctly and it looks like this:
Tried to search for existing solutions on github, but so far did not find anything useful. Will continue to look further of course, I bet there are projects that use it for case similar to mine.
Beta Was this translation helpful? Give feedback.
All reactions