SDK Overview
SkyState ships JavaScript/TypeScript SDKs for public state, user state, and hosted end-user auth. Use public state for application config, feature flags, public settings, and client-visible catalog or inventory values.
| Package | Description |
|---|---|
@skystate/core | Framework-agnostic client library. Use this for any JavaScript runtime - Node.js, Vanilla JS, or when building your own framework integration. |
@skystate/react | React bindings built on @skystate/core. Provides a context provider and hooks for public state, user state, and hosted auth. |
Basic Examples
React
tsx
import { SkyStateProvider, usePublicState, useUserState } from '@skystate/react';
function AppRoot() {
return (
<SkyStateProvider account="acc_example" project="my-project" environment="production">
<App />
</SkyStateProvider>
);
}
function App() {
const { value: banner } = usePublicState('banner', { text: 'Welcome' });
const { value: theme, set: setTheme } = useUserState('theme', 'dark');
return (
<>
<p>{banner.text}</p>
<button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
Theme: {theme}
</button>
</>
);
}Core
ts
import { createSkyStateClient } from '@skystate/core';
const client = createSkyStateClient({
account: 'acc_example',
project: 'my-project',
environment: 'production',
});
await client.init();
const banner = client.publicState.get('banner', { text: 'Welcome' });
client.setAuthTokens({ idToken, refreshToken });
client.userState.set('theme', 'dark');Supported Platforms
Both packages run in modern browsers and Node.js 18+.
- Browser: Vite, webpack, Rollup, esbuild, or any bundler that supports ESM
- Node.js: 18+ (uses the built-in
fetchAPI) - React: 18+
- Framework support: The core package is framework-agnostic. The React package targets React 18 and React 19.
Public Contract
| Behavior | Detail |
|---|---|
| Public state | Readable before login. Use it for application config, feature flags, public settings, and catalog or inventory values. Use publicState.get() in core or usePublicState() in React. |
| User state | Requires a signed-in end user. Use userState.get/set/draft() in core or useUserState() in React. |
| Auth | React starts hosted login through useAuth().loginWithRedirect(). Core accepts tokens from an auth flow with setAuthTokens(). |
| Provider scope is mount-time | Switching account, project, or environment requires remounting SkyStateProvider with a new React key. |
| Keyed public reads return value only | Use usePublicState(key, fallback?) for { value }, and usePublicState() with no args for subsystem status. |
| Keyed user reads return value, set, and draft | Use useUserState(key, fallback?) for { value, set, draft }, and useUserState() with no args for subsystem status. |
| SDK v1 is value-only | Keyed SDK calls expose values, setters, drafts, and subsystem status. Use the console, CLI, or REST API for inspection, audit, or history metadata. |
| Production cache TTL: 900 seconds | Public state reads are cached 15 minutes in production. |
| Dev/staging cache TTL: 10 seconds | Development and staging public state is cached for 10 seconds. |
| Fixed environments | Only development, staging, and production are valid environment slugs. |
| Account/project route changes break URLs | SDK clients must use the current account route identifier and project identifier. |
Installation
For React applications (@skystate/react on npm):
bash
npm install @skystate/reactFor framework-agnostic JavaScript or Node.js (@skystate/core on npm):
bash
npm install @skystate/core@skystate/react depends on @skystate/core and re-exports the types you need, so you do not need to install @skystate/core separately when using React.
Sections
@skystate/core
Framework-agnostic client. Covers createSkyStateClient, public state, and user state.
- Client -- initialization, reading values, subscribing to changes
- Environments -- how environment slugs work
@skystate/react
React bindings. Covers the provider, hooks, and TypeScript patterns.
- SkyStateProvider -- context provider props and setup
- useAuth and status hooks -- auth state, auth actions, and subsystem status
- usePublicState -- read public state keys
- useUserState -- read, write, and draft user state