Quick Start
Basic Store
Section titled “Basic Store”Create a store with initial state:
import { createStore } from '@standard-store/store';
// Create a store with initial stateconst store = createStore({ count: 0, name: 'John',});
// Get current stateconst state = store.getState();console.log(state); // { count: 0, name: 'John' }
// Update statestore.setState({ count: 1 });
// Subscribe to changesconst unsubscribe = store.subscribe((state) => { console.log('State updated:', state);});
// Unsubscribe when neededunsubscribe();React Integration
Section titled “React Integration”Create a custom hook for React components:
import { createStoreHook } from '@standard-store/react';
// Create a custom hookconst useStore = createStoreHook(store);
function MyComponent() { const state = useStore();
return ( <div> <p>Count: {state.count}</p> <p>Name: {state.name}</p> <button onClick={() => store.setState({ count: state.count + 1 })}> Increment </button> </div> );}With Persistence
Section titled “With Persistence”Persist state to localStorage automatically:
import { createStore } from '@standard-store/store';import { localStorageAdapter } from '@standard-store/adapters';
const store = createStore( { count: 0, name: 'John', }, { adapter: localStorageAdapter('my-app-store'), });
// State will automatically persist to localStorage// and restore on page reload!Next Steps
Section titled “Next Steps”- Learn about Core Concepts
- Explore Guides
- Check API Reference