Skip to content

How to update the context set in a route loader? #10420

Closed Answered by sergiodxa
davidbielik asked this question in Q&A
Discussion options

You must be logged in to vote

The context received by loaders and actions, called AppLoadContext, can't be changed from inside loaders and actions, that context is used by the HTTP server to inject values into the Remix loaders/actions.

Also React context won't work in loaders and actions, they run outside React and in the server, so you can't call useContext inside your loaders and actions.

And if you want to share data from a parent route to children routes instead of creating a custom context you can use the useRouteLoaderData hook, if you want to access the root loader data you can do useRouteLoaderData("root"), other routes will need you to pass the route id.

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@akomm
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by davidbielik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants