SimpleR State
SimpleR State is an ultra-lightweight library that provides the simplest state management for React.
This library is an evolution of React Entities.
Two Easy Steps!
Step 1: Create an entity (shared state) and actions (updater functions)
import { entity } from 'simpler-state'
export const counter = entity(0)
export const increment = by => {
counter.set(counter.get() + by)
}
export const decrement = by => {
counter.set(counter.get() - by)
}
Step 2: Use the entity in your components with hooks
import { useEntity } from 'simpler-state'
import { counter, increment, decrement } from 'counter'
const CounterView = () => {
const count = useEntity(counter)
return (
<>
<div>{count}</div>
<button onClick={() => increment(1)}> + </button>
<button onClick={() => decrement(1)}> - </button>
</>
)
}
It's that simple!