You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[React Router v7](https://reactrouter.com/) is a full-stack web framework for building React applications. You can query your D1 database from React Router using the [data loading](https://reactrouter.com/start/framework/data-loading) API with the `loader` function and `useLoaderData` hook.
14
+
[React Router v7](https://reactrouter.com/) is a full-stack web framework for building React applications. You can query your D1 database from React Router using the [data loading](https://reactrouter.com/start/framework/data-loading) API with the `loader` function.
15
15
16
16
## Set up a React Router project with D1
17
17
@@ -61,59 +61,44 @@ import type { Route } from "./+types/users";
For full type safety, extend the `CloudflareEnvironment`interface in your Worker entry file:
84
+
The React Router Cloudflare template includes a `cf-typegen` script that runs [`wrangler types`](/workers/wrangler/commands/#types) to generate an `Env`interface from your Wrangler configuration. After adding the D1 binding to your Wrangler configuration, run the script to generate types:
The `workers/app.ts` entry file in the template already uses this `Env` type, so your `context.cloudflare.env.DB` calls will be fully typed without any manual configuration.
99
+
100
+
:::note
101
+
Run `npm run cf-typegen` whenever you change bindings in your Wrangler configuration to keep your types in sync.
102
+
:::
103
+
119
104
For more information on using bindings with React Router, refer to the [React Router framework guide](/workers/framework-guides/web-apps/react-router/#use-bindings-with-react-router).
0 commit comments