SimpleR State
SimpleR State is an ultra-lightweight library that provides the simplest state management for React.
It is part of the upcoming SimpleR collection of all things that make React development a breeze. This library is an evolution of React Entities.
Two Easy Steps!
Step 1: Create an entity (shared state) and actions
const counter = entity(0)
const increment = by => {
counter.set(counter.get() + by)
}
const decrement = by => {
counter.set(counter.get() - by)
}
Step 2: Use the entity in your components
const CounterView = () => {
const count = useEntity(counter)
return (
<>
<div>{count}</div>
<button onClick={() => increment(1)}> + </button>
<button onClick={() => decrement(1)}> - </button>
</>
)
}
It's that simple!