Back to Rivet

State Management

examples/state-vercel/README.md

2.2.11.4 KB
Original Source

Note: This is the Vercel-optimized version of the state example. It uses the hono/vercel adapter and is configured for Vercel deployment.

State Management

Demonstrates persistent state management in Rivet Actors with automatic state saving and restoration.

Getting Started

sh
git clone https://github.com/rivet-dev/rivet.git
cd rivet/examples/state
npm install
npm run dev

Features

  • Persistent state: Actor state automatically saved and restored across restarts
  • Typed state management: Full TypeScript type safety for state objects
  • State initialization: Define initial state with createState or state property
  • Automatic serialization: State changes automatically persisted without manual saves

Implementation

This example demonstrates state management in Rivet Actors with a simple counter:

  • Actor Definition (src/backend/registry.ts): Defines the counter actor with a count state that persists across actor restarts

Resources

Read more about state management, actions, and lifecycle hooks.

License

MIT