Environments
SkyState public state and user state are stored per environment. Pass the environment slug as the environment option when creating a client.
Environment Slugs
The environment option accepts one of three fixed values: 'development', 'staging', or 'production'.
Production public-state reads are cached for 900 seconds. Development and staging reads are cached for 10 seconds.
Setting the Environment
ts
import { createSkyStateClient } from '@skystate/core';
const client = createSkyStateClient({
account: 'acc_example',
project: 'my-project',
environment: 'production',
});
await client.init();To vary the environment by build, pass any build-time variable that resolves to the right slug. The SDK does not read environment from any env var — you supply it:
ts
// Any build variable works. This example uses Vite's built-in MODE
// (resolves to 'development' in dev server, 'production' in vite build,
// or a custom value with vite build --mode staging).
const mode = import.meta.env.MODE as string;
const client = createSkyStateClient({
account: 'acc_example',
project: 'my-project',
environment: mode === 'staging' ? 'staging' : mode === 'development' ? 'development' : 'production',
});In React, pass the environment slug to SkyStateProvider via the environment prop. It defaults to 'development' if omitted.