β‘ Ultra-lightweight state management for React 18+ applications (~950B gzipped)
| π¦ NPM Package | π Bundle Size | β GitHub Stars | π₯ Downloads |
|---|---|---|---|
| react-constore | ~950B gzipped | β Star us! | π NPM Trends |
- β TypeScript Ready - Full type safety out of the box
- β React 18+ Compatible - Concurrent features supported
- β Zero Dependencies - No external packages needed
- β
Devtools - use
Redux-Devtoolsfor debugging - β SSR Ready - Works with Next.js App Router
- β Tree Shakeable - Only bundle what you use
- β MIT Licensed - Free for commercial use
- π Documentation: GitHub Repository
- π¦ Install:
npm install react-constore - π Bundle Analysis: Bundle Phobia
- π Download Stats: NPM Package
- π Issues & Support: GitHub Issues
// Traditional React state management β
const [count, setCount] = useState(0);
const [user, setUser] = useState({ name: 'Guest' });
const [todos, setTodos] = useState([]);
// Props drilling nightmare... π±
// With React ConStore β
const store = createStore({
count: 0,
user: { name: 'Guest' },
todos: []
});
// Use anywhere, anytime π
const [count, setCount] = store.useStoreKey('count');| Feature | Description | Benefit |
|---|---|---|
| πͺΆ Ultra Lightweight | Less than 1KB gzipped | Faster bundle, better performance |
| βοΈ React 18/19 Ready | Concurrent features, automatic batching | Future-proof your app |
| π― Smart Re-renders | Deep equality checks | Only render when data actually changes |
| π Selective Subscriptions | Subscribe to specific keys | Granular control over updates |
| π Full TypeScript | Complete type safety | Catch bugs at compile time |
| π SSR Compatible | Next.js 13+ App Router | Server-side rendering support |
# npm
npm install react-constore
# yarn
yarn add react-constore
# pnpm
pnpm add react-constore'use client'; // for Next.js App Router
import createStore from 'react-constore';
// 1. Create your store
const store = createStore({
count: 0,
user: { name: 'Guest', age: 25 },
todos: [],
theme: 'light'
});
// 2. Use in components
function Counter() {
const [count, setCount] = store.useStoreKey('count');
return (
<div>
<h2>Count: {count}</h2>
<button onClick={() => setCount(count + 1)}>
Increment
</button>
<button onClick={() => setCount(c => c + 1)}>
Functional Update
</button>
</div>
);
}
function UserProfile() {
const [user, setUser] = store.useStoreKey('user');
return (
<div>
<h2>{user.name} (Age: {user.age})</h2>
<button onClick={() => setUser({ ...user, age: user.age + 1 })}>
Happy Birthday! π
</button>
</div>
);
}
// 3. Components automatically sync!
function App() {
return (
<div>
<Counter />
<UserProfile />
</div>
);
}- Hooks Guide -
useStoreKey(),useStoreKeys(),useStore() - Store API -
getState(),setState(),subscribe()
- DevTools - Debugger mode and built-in middlewares
- Advanced Patterns - Computed values, actions, middleware
- React Integration - React 18+, Next.js, React Native
- Migration Guide - From Redux, Zustand, React Context API
| Library | Size (gzipped) | Features |
|---|---|---|
| React ConStore | ~950B | β Hooks β TypeScript β SSR β DevTools β Middleware β Persist |
| Redux Toolkit | ~3KB | β DevTools β Middleware β Time Travel β Simple API |
| Zustand | ~600B | β Simple β Middleware β Built-in TypeScript |
| Jotai | ~4KB | β Atomic β TypeScript β Learning Curve |
Use React ConStore when:
- β You want minimal bundle size
- β Simple to medium complexity apps
- β TypeScript-first development
- β React 18+ features are important
- β Devtools for debugging
- β Custom middleware
Consider alternatives when:
- π€ Redux Toolkit: Need time-travel debugging, complex middleware
- π€ Zustand: Need advanced features (immer, persist, devtools)
- π€ Jotai: Bottom-up atomic state management
- π€ Context API: Very simple, component-local state
MIT Β© Mostafa Rastegar
Made with β€οΈ for the React community