onyxx
v1.0.2
Published
Minimal reactive store for React
Downloads
107
Readme
Onyxx
Onyxx is a lightweight, zero-dependency state management library for React — powered by useSyncExternalStore and a modern, minimal API.
✨ Features
- ⚡ Tiny and Fast – <1KB gzipped, with efficient updates via
useSyncExternalStore - 🧠 React-like API – Familiar
useState-like syntax - 🎯 Selector Support – Subscribe to specific fields for optimal performance
- 🎁 Partial Updates – Like
setState, but globally shared - 💡 No Provider Needed – No context, no boilerplate
- 🛠️ TypeScript-first – Full type safety and autocompletion
- 🌍 Multi-store Friendly – Create as many independent stores as needed
📦 Installation
npm install onyxx
# or
yarn add onyxxUsage
Here's a quick example of how to use
import { onyxx } from "onyxx";
const [useCounter, setCounter] = onyxx(0);
// Component using the shared counter state
export default function Counter() {
const count = useCounter((state) => state);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCounter((count) => count + 1)}>
Increment
</button>
</div>
);
}
function App() {
return (
<div>
<Counter />
<Counter />
</div>
);
}