#Do we have any way to use root context or routing context in react-router loader and react

1 messages · Page 1 of 1 (latest)

plush sparrow
#

I' using AuthContext outside RouterProvider

spare sonnet
#

no, RR loaders run outside React so there's no way to access React's context there

#

in a future RR release they will add a context parameter to RouterProvider so in that case you could do something like this

<AuthProvider>
  {auth => <RouterProvider router={router} context={{ auth }} />}
</AuthProvider>

and in your loaders will get this context object as an argument of the loader along request and params, but this is not released yet

#

my recommendation, even once RouterProvider accepts this context object, is to avoid keeping things like auth as a React state

plush sparrow
#

I'm using RouterProvider in RR v7, the context isn't declared in RouterProvider coolpanic

spare sonnet
#

it's not yet released

#

there was a PR to add it

#

I'm not sure if it's merged yet