State
State

Overview

A package for working with React state (new tab) in a more ergonomic way.

npm versionnpm downloadsBundlephobia

Installation

Required dependencies

This package relies on React hooks (new tab) and thus requires version 16.3 or higher.

# npm
npm i --save @weser/state

# yarn
yarn add @weser/state

# pnpm
pnpm add @weser/state

Motivation

There are many ways to handle state in React, including the built-in useState (new tab), useReducer (new tab) or the fairly new useOptimistic (new tab).
The first two are great, but lack first-class support for side effects (unless you use useEffect (new tab), which has its very own set of problems) while the latter doesn't really have the most ergonomic API.
That's why I decided to create this package to provide a more ergonomic, low-level API for state management.

Benefits

This package provides a more ergonomic, low-level API for state management including reducers with side effects and a useState-like hook with optimistic updates.

On this page