Then call doSomething in any loader, action, or another middleware, and you will have access to the context and request objects without passing them around.
You can pair this with any other middleware that uses the context to simplify using their returned getters.
The Context Storage middleware stores the Router context provider and request in AsyncLocalStorage and gives you functions to access it in your code.
To use it, you need to add it to the
unstable_middleware
array in yourapp/root.tsx
file.And you can use the
getContext
andgetRequest
functions in your function to get the context and request objects.Then call
doSomething
in any loader, action, or another middleware, and you will have access to the context and request objects without passing them around.You can pair this with any other middleware that uses the context to simplify using their returned getters.
Now instead of calling
getBatcher(context)
you can just callgetBatcher()
and it will return the batcher instance.Author
Sergio XalambrÃ