MostafaRastegar / react-constore

Ultra-lightweight state management for React 18+ applications

Repository from Github https://github.comMostafaRastegar/react-constoreRepository from Github https://github.comMostafaRastegar/react-constore

React ConStore

⚑ Ultra-lightweight state management for React 18+ applications (~950B gzipped)

πŸ“Š Quick Stats

πŸ“¦ NPM Package πŸ“ Bundle Size ⭐ GitHub Stars πŸ“₯ Downloads
react-constore ~950B gzipped ⭐ Star us! πŸ“ˆ NPM Trends

βœ… Features

  • βœ… TypeScript Ready - Full type safety out of the box
  • βœ… React 18+ Compatible - Concurrent features supported
  • βœ… Zero Dependencies - No external packages needed
  • βœ… Devtools - use Redux-Devtools for debugging
  • βœ… SSR Ready - Works with Next.js App Router
  • βœ… Tree Shakeable - Only bundle what you use
  • βœ… MIT Licensed - Free for commercial use

πŸ”— Quick Links

πŸš€ Why React ConStore?

// 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');

✨ Key Features

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

πŸ“¦ Installation

# npm
npm install react-constore

# yarn
yarn add react-constore

# pnpm
pnpm add react-constore

🎯 Quick Start

'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>
  );
}

πŸ“š Documentation

πŸš€ Getting Started

πŸ“– API Reference

  • Hooks Guide - useStoreKey(), useStoreKeys(), useStore()
  • Store API - getState(), setState(), subscribe()

πŸ”§ Advanced Usage

πŸ”„ Migration & Comparison

πŸ“š Best Practices & Help

πŸ“Š Bundle Size Comparison

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

πŸ†š When to Use

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

πŸ“„ License

MIT Β© Mostafa Rastegar


Made with ❀️ for the React community

About

Ultra-lightweight state management for React 18+ applications


Languages

Language:TypeScript 90.2%Language:JavaScript 9.8%