How do I use the new context API with Express and getLoadContext? #13370
Unanswered
purplesquirrels
asked this question in
Q&A
Replies: 1 comment 2 replies
-
You will need to configure Vite to build the Express server along the app in order to be able to share the context object |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently migrated an app from Remix to RR7 and everything went smoothly. I'm using a custom Express server with socket.io, and I need to pass the IO object into RR loaders/actions via context which is working fine on the old context API. But I'm interested in trying out middleware and need to migrate to the new context API and I'm struggling to figure out how to make it work. The guide is not clear to me.
In the express server I'm using getLoadContext to provide the IO object:
But instead of returning an object, according to the guide I need to return a map with a key using unstable_createContext:
The issue I have is that if I create and import the context in the Express server file, my RR app doesn't have access to the context object to retrieve it with
context.get(socketContext)
. And if I create the context in the RR app then the Express server doesn't have access to the context object to set it in getLoadContext.What am I missing here?
Beta Was this translation helpful? Give feedback.
All reactions