Introduction

State management based on React Hooks.

tap is a state management library based on React Hooks.

It lets you build and manage your application state with the APIs and mental model you already use in React, organized around one new primitive: the Resource.

A Resource does for state what a component does for UI. It turns stateful behavior into a reusable, composable building block—but returns state and methods instead of JSX.

Resources organize like components, but execute like Hooks.

Resources are the unit of state composition

counter.jsx

import { useState } from "react";
const useCounter = () => {
const [count, setCount] = useState(0);
const increment = () => setCount((value) => value + 1);
return { count, increment };
};

Step 1 of 7

Write a Hook

resource() turns a Hook into a Resource. Use useResource to compose one Resource or useResources to compose a keyed collection.

Nested Resources behave as if their Hook logic were inlined, so effects follow declaration order—not component-tree order. See Differences from React for details.

Next steps