Install
Install the package from npm. It needs React 18 or 19.
npm install @khanglvm/reactThe package ships ES modules with TypeScript declarations, and Immer is its only dependency. In Next.js App Router, files that use the hooks need 'use client' at the top; the Next.js guide lists what runs where.
@khanglvm/react
React utilities for TypeScript apps in React or Next.js App Router, each one usable on its own.
Shared state with createContextState
createContextState<State>() creates a typed store and the hooks to use it. A Provider owns the state. Components read slices with selectors, and each one rerenders only when its selected value changes. Updates take a partial object or an Immer draft function, and each update returns a function that undoes it.