State Management

State Management

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

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.