Data Context #11565
Replies: 6 comments 10 replies
-
I prefer this one: import { LoaderFunctionArgs } from 'react-router';
type Vars = {
db: OutDb;
}
function DbMiddleware({ context, request }: LoaderFunctionArgs<Vars>) {
let db = getDBFromRequest(request)
context.set('db', db);
}
// get a context in a loader
export async function loader({ context }: LoaderFunctionArgs<Vars>) {
let db = context.get('db')
// ...
} We don't need to import runtime code for type systems, Type System should not be invaded by runtime code. |
Beta Was this translation helpful? Give feedback.
-
What will happen on Remix/RRv7 when |
Beta Was this translation helpful? Give feedback.
-
When run on Cloudflare Pages/Workers, will a React Router 'Data Context' be a per-request instance, or will it be a global/potentially shared across multiple requests? (the latter behaviour would match |
Beta Was this translation helpful? Give feedback.
-
What's the status of this? I'm looking to set values to a context but can't find |
Beta Was this translation helpful? Give feedback.
-
Api is a bit confusing, I wanted to do auth before loaders in middleware:
But got an error I did a refactoring to make it work, but this is a bit counter-intuitive:
Can we expose response in middleware without calling loaders to make it a bit simpler? |
Beta Was this translation helpful? Give feedback.
-
Is there any inbuilt way of accessing data through store like in zustand in react router?, I'm using context in middleware to store permissions and access in different route but eventually doing permission props drilling |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Data context allows you to create a value in one place and share it across loaders, actions, and middleware.
Beta Was this translation helpful? Give feedback.
All reactions