Installation
Get started with Unistash
Installation
Choose Your Adapter
Unistash supports multiple state management libraries. Choose the one that fits your needs:
Zustand
npm install @unistash/zustand zustandBest for:
- Simplicity and speed
- Small bundle size (~1KB)
- No Provider wrapper needed
- Quick prototypes and small apps
Trade-offs:
- Fewer debugging tools
- Smaller ecosystem
Learn more about Zustand adapter →
Jotai
npm install @unistash/jotai jotaiBest for:
- Atomic state management
- Fine-grained updates
- React 18 features (Suspense, transitions)
- Derived state patterns
Trade-offs:
- Requires Provider wrapper
- Slightly more complex mental model
Learn more about Jotai adapter →
Redux Toolkit
npm install @unistash/redux @reduxjs/toolkit react-reduxBest for:
- Enterprise applications
- Redux DevTools integration
- Large teams familiar with Redux
- Time-travel debugging
- Complex state logic
Trade-offs:
- Larger bundle size (~8KB)
- Requires Provider wrapper
- More boilerplate (even with RTK)
Learn more about Redux adapter →
Coming Soon
- Valtio - Proxy-based state (Poimandres)
- Recoil - Facebook's state library
- MobX - Observable state management
- XState - State machines
Requirements
- React: 18.0 or higher
- TypeScript: 5.0 or higher (recommended)
- Node.js: 18.0 or higher
Quick Comparison
| Adapter | Bundle Size | Provider | DevTools | Best For |
|---|---|---|---|---|
| Zustand | 🟢 ~1KB | ❌ No | ⚠️ Extension | Small apps, prototypes |
| Jotai | 🟢 ~3KB | ✅ Yes | ⚠️ Extension | Atomic updates, React 18 |
| Redux | 🟡 ~8KB | ✅ Yes | ✅ Built-in | Enterprise, debugging |
TypeScript Support
Unistash is written in TypeScript and provides excellent type inference out of the box:
const useStore = createStore({
state: { count: 0 }, // Type inferred as number
actions: {
increment: (state) => ({ count: state.count + 1 }),
// state is fully typed!
},
computed: {
doubled: (state) => state.count * 2,
// Return type inferred automatically
},
});
// In component - full autocomplete!
const { count, doubled, actions } = useStore();
// ^typed ^typed ^typedNo additional setup needed!
Switching Adapters
One of Unistash's superpowers is switching adapters with minimal changes:
// Step 1: Change the import
// import { createStore } from '@unistash/zustand';
import { createStore } from '@unistash/redux';
// Step 2: Your code stays the same!
const useStore = createStore({
state: { count: 0 },
actions: {
increment: (state) => ({ count: state.count + 1 }),
},
});
// Step 3: Add Provider if needed (Redux/Jotai)
import { UnistashProvider } from '@unistash/redux';
function App() {
return (
);
}That's it! Your components don't need to change at all.
Next Steps
- API Reference - Complete API documentation
- Zustand Adapter - Learn about Zustand
- Jotai Adapter - Learn about Jotai
- Redux Adapter - Learn about Redux Toolkit
- Migration Guide - Migrating existing apps