React Router v7
Add voidPlugin() alongside the React Router v7 Vite plugin to use Void's database, storage, and deployment features. Void includes the Cloudflare adapter.
Setup
1. Create a new project
npm create react-router@latest my-app
cd my-app2. Install dependencies
npm install -D void3. Configure vite.config.ts
import { reactRouter } from '@react-router/dev/vite';
import { defineConfig } from 'vite';
import { voidPlugin } from 'void';
export default defineConfig({
plugins: [
voidPlugin(), // must come before the framework plugin
reactRouter(),
],
});For React Router v7, set future.v8_viteEnvironmentApi to true in react-router.config.ts to enable the Vite Environment API.
If you use React Router 8 with prerender in react-router.config.ts, set the build command before your first deployment:
// void.config.ts
import { defineConfig } from 'void/config';
export default defineConfig({
inference: { build: 'react-router build' },
});This lets the build finish after prerendering so Void can upload the app. The default Vite build can stay open at that point. React Router issue
4. Deploy
void connect --platform cloudflare
void deployOn the first command, sign in and select your Cloudflare account. void deploy builds the app and publishes it to that account. To deploy to your team’s Void platform, see Deployment.
Using Void Features
Use Void resources in loaders and actions. For authentication, use your framework’s Better Auth integration.
Database
To show the users in your database, query the users table in the route’s loader. React Router passes the result to the route component.
import { users } from '@schema';
import { db } from 'void/db';
import type { Route } from './+types/users';
export async function loader({}: Route.LoaderArgs) {
return { users: await db.select().from(users) };
}Other resources
See supported resources and background jobs for KV, storage, AI, cron jobs, and queues.
To run a queue consumer locally, start the dev server and use the manual queue trigger. Use the dev server’s port and the token in .void/dev-trigger-token. Calling send() in dev or preview accepts the message without running the consumer. Preview reads queues/ and env.ts from your project, so keep both as they were when you built the app.
Environment Variables
Declare variables in env.ts and read them with import { env } from "void/env". See Environment Variables for local values, production secrets, and public VITE_* values.
Read server secrets in a .server.ts companion module and import it into your loader or action. Void rejects server-secret reads in route files that also contain browser components.
Custom Worker Entry
To customize how your Cloudflare Worker handles requests or add named exports such as a WorkerEntrypoint, set cloudflare.main to a path relative to your app root in void.config.ts.
import { defineConfig } from 'void/config';
export default defineConfig({
cloudflare: { main: './worker.ts' },
});In worker.ts, default-export the Worker handler and forward page requests to React Router.
import { createRequestHandler } from 'react-router';
const handleRequest = createRequestHandler(
// @ts-expect-error React Router's Vite plugin provides this module.
() => import('virtual:react-router/server-build'),
import.meta.env.MODE,
);
export default {
fetch(request: Request) {
return handleRequest(request);
},
};Accessing Bindings Directly
You can also access Cloudflare bindings via the cloudflare:workers module:
import { env } from 'cloudflare:workers';
const { results } = await env.DB.prepare('SELECT * FROM users').all();