Kosha is a minimal global state management solution tailored for modern React applications. At only 420 bytes (minzipped), it provides exceptional performance and simplicity for developers focused on clean and efficient code.
-
Ultra-Lightweight
- Minzipped size: 571 bytes, ideal for performance-critical projects.
-
Optimized Re-renders
- Components only re-render when the selector output changes.
- Example:
const count = useKosha(state => state.count);
-
Partial State Updates
- Update specific parts of the state easily without spreading:
set({ count }); set(state => ({ count: state.count + 1 }));
- Update specific parts of the state easily without spreading:
-
Direct Store Updates
- Use
useKosha.set
to update the entire store directly:useKosha.set({ count: 42, user: "John Doe" });
- Use
-
Flexible Consumption
- Use the entire store or specific selectors as needed:
const { count, setCount } = useKosha();
- Use the entire store or specific selectors as needed:
-
Concurrent Rendering Ready
- Built on React’s
useSyncExternalStore
, ensuring compatibility with React 18+ features.
- Built on React’s
Install Kosha using your preferred package manager:
pnpm add kosha
or
npm install kosha
or
yarn add kosha
import { create } from "kosha";
const useKosha = create(set => ({
count: 0,
increment: () => set(state => ({ count: state.count + 1 })),
}));
const Counter = () => {
const { count, increment } = useKosha();
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
};
const Counter = () => {
const count = useKosha(state => state.count);
const increment = useKosha(state => state.increment);
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
};
You can also use useKosha.set
to update the entire store directly:
useKosha.set({ count: 42, user: "John Doe" });
Yes! You can handle async actions with callbacks or promises directly within your store functions.
Kosha relies on React’s useSyncExternalStore
for smooth integration with React’s latest features, including concurrent rendering.
We welcome your contributions! If you encounter issues or have suggestions, please submit them on the Kosha GitHub Repository.
Kosha is licensed under the MPL-2.0 open-source license.
Check out our courses or sponsor our work.
Built with 💖 by Mayank Kumar Chaudhari