#loader/action context in browser router

1 messages · Page 1 of 1 (latest)

fair spindle
#

in remix you can pass a context that is available in loaders and actions
is that feature not available in react router?
it seems like there should be some way to inject it, but im not finding anything in the docs or types

uncut schooner
#

There is not equivalent at the moment in createBrowserRouter. That is a Remix feature for passing server-specific request info into your Remix loaders. When running in the browser, you've got access to the full scope so generally you can get by by just grabbing the thing you need. Generally module scope is recommended, or you could just leverage a shared property on window

fair spindle
#

hm
my use-case is that i want to be able to run graphql requests in actions/loaders in both client and server context
ideally i could pass a function graphql() into the context, and in the browser it would send an http request, and on the server the loader would execute the graphql request directly against the schema
i have that graphql function for both contexts, but i cant figure out how to inject the right one depending on context