Data Context #11565
ryanflorence
announced in
Official RFCs
Data Context
#11565
Replies: 3 comments 8 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.
2 replies
-
What will happen on Remix/RRv7 when |
Beta Was this translation helpful? Give feedback.
5 replies
-
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.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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