docs/versioned_docs/version-1.12.0/00100-intro/00200-quickstarts/00100-react.md
import { InstallCardLink } from "@site/src/components/InstallCardLink"; import { StepByStep, Step, StepText, StepCode } from "@site/src/components/Steps";
Get a SpacetimeDB React app running in under 5 minutes.
This will start the local SpacetimeDB server, publish your module, generate TypeScript bindings, and start the React development server.
</StepText>
<StepCode>
spacetime dev --template react-ts my-spacetime-app
</StepCode>
The template includes a basic React app connected to SpacetimeDB.
</StepText>
Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `client/src/App.tsx` to build your UI.
</StepText>
<StepCode>
my-spacetime-app/
├── spacetimedb/ # Your SpacetimeDB module
│ └── src/
│ └── index.ts # Server-side logic
├── client/ # React frontend
│ └── src/
│ ├── App.tsx
│ └── module_bindings/ # Auto-generated types
└── package.json
</StepCode>
Tables store your data. Reducers are functions that modify data — they're the only way to write to the database.
</StepText>
<StepCode>
import { schema, table, t } from 'spacetimedb/server';
export const spacetimedb = schema(
table(
{ name: 'person', public: true },
{
name: t.string(),
}
)
);
spacetimedb.reducer('add', { name: t.string() }, (ctx, { name }) => {
ctx.db.person.insert({ name });
});
spacetimedb.reducer('say_hello', (ctx) => {
for (const person of ctx.db.person.iter()) {
console.info(`Hello, ${person.name}!`);
}
console.info('Hello, World!');
});
</StepCode>
"Alice"
spacetime call <database-name> say_hello
spacetime logs <database-name> 2025-01-13T12:00:00.000000Z INFO: Hello, Alice! 2025-01-13T12:00:00.000000Z INFO: Hello, World!
</StepCode>
</Step>
</StepByStep>
## Next steps
- See the [Chat App Tutorial](../00300-tutorials/00100-chat-app.md) for a complete example
- Read the [TypeScript SDK Reference](../../00200-core-concepts/00600-client-sdk-languages/00700-typescript-reference.md) for detailed API docs