Cotton Box is a lightweight state management library designed for flexibility and simplicity.
It works seamlessly with React Hooks while remaining usable outside React, requires no providers or boilerplate, and supports advanced features like async state updates, customizable equality checks, and declarative lifecycle management.
| Packages | Stats | |
|---|---|---|
cotton-box |
Changelogs | |
cotton-box-react |
Changelogs |
- ⚡️ Lightweight & fast
- 🧩 No providers or boilerplate
- 🎯 Customizable equality checking
- 🌱 Declarative lifecycle management
- 🌐 Library/Framework agnostic
- ⏸️ Temporarily unwatch state in hooks
- ⏳ Supports async state updates
- 📚 Fully typed API
import { SimpleStateManager } from 'cotton-box'
const CounterState = new SimpleStateManager(0)CounterState.set(42)CounterState.set((c) => c + 1)const counter = CounterState.get()const unwatch = CounterState.watch((counter) => {
console.log(counter)
})
// ... other code here ...
unwatch()// Wait for counter to reach 100
await CounterState.wait(100)import { useSimpleStateValue } from 'cotton-box-react'
function App() {
const counter = useSimpleStateValue(CounterState)
return <p>Counter: {counter}</p>
}