Packages | Stats |
---|---|
cotton-box |
|
cotton-box-react |
- Lightweight & fast
- Declarative lifecycle management
- Supports asynchronous set-state functions
- Official bindings for React available
View documentations (still a work-in-progress)
import { StateManager } from 'cotton-box'
const CounterState = new StateManager(42)
// Set, get, reset
CounterState.set(7)
console.log(CounterState.get()) // 7
CounterState.reset()
console.log(CounterState.get()) // 42
// Watch for state changes
const unwatch = CounterState.watch((state) => {
console.log(state)
})
// Wait for state to change
// Promise will resolve when value matches
await CounterState.wait(50)
import { useStateValue } from 'cotton-box-react'
function App() {
const counter = useStateValue(CounterState)
return <h1>Counter: {counter}</h1>
}
- Ko-fi:
ko-fi.com/glyphcat
- BTC:
bc1q5qp6a972l8m0k26ln9deuhup0nmldf86ndu5we