Skip to main content

Stan.js

Lightweight and flexible state management library for React applications and vanilla JavaScript

Why Stan.js?

Stan.js provides a simple and powerful approach to state management without the complexity of traditional solutions

Performance Optimized

Minimal re-renders with intelligent subscription system that only updates components when their specific data changes

TypeScript First

Built with TypeScript for excellent IntelliSense and type safety. Get autocomplete for all your store values and actions

Built-in Persistence

Persist state to localStorage, sessionStorage, or React Native MMKV with a simple wrapper function

Simple Configuration

Create a store with a single function call. No boilerplate, no complex setup, just write your state

Zero Dependencies

Extremely lightweight with no external dependencies. Keep your bundle size small and focused

Universal Support

Works with React, React Native, Next.js SSR, Astro, and vanilla JavaScript. One solution for all platforms

Quick start

Get up and running with Stan.js in just a few steps

1

Install the package

Install stan-js using your preferred package manager:
npm install stan-js
2

Create a store

Create a store with your initial state. Each key in your store creates a separate subscription for optimal performance:
store.ts
import { createStore } from 'stan-js'

export const { useStore } = createStore({
  count: 0,
  user: '',
  theme: 'light'
})
3

Use in your components

Access your store values and automatically generated setter functions in any React component:
App.tsx
import { useStore } from './store'

function App() {
  const { count, setCount } = useStore()

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(prev => prev + 1)}>
        Increment
      </button>
    </div>
  )
}
Stan.js automatically generates setter functions for each state key. For a key named count, you get setCount. For user, you get setUser.

Explore the documentation

Learn about core concepts and advanced features

Core Concepts

Understand how stores, subscriptions, and computed values work

React Integration

Learn how to use Stan.js with React hooks and patterns

Persistence

Persist your state to localStorage, sessionStorage, or MMKV

Vanilla JavaScript

Use Stan.js without React in any JavaScript environment

TypeScript Guide

Leverage TypeScript for type-safe state management

Performance Tips

Optimize your application with best practices

Ready to get started?

Jump into the quickstart guide and build your first Stan.js application in minutes

Get Started Now

Build docs developers (and LLMs) love