JotaiJotai

状態
Primitive and flexible state management for React

Introduction

Welcome to the Jotai documentation! Jotai is a primitive and flexible state management library for React.

It takes a bottom-up approach to global React state management with an atomic model inspired by Recoil. One can build state by combining atoms and renders are optimized based on atom dependency. This solves the extra re-render issue of React context and eliminates the need for memoization.

Features

  • Minimal API
  • TypeScript oriented
  • Tiny core bundle size (2kb)
  • Many extra utilities and integrations
  • Supports Next.js, Gatsby, Remix, and React Native
  • Great developer experience with React Fast Refresh

Core

Jotai has a very minimal API, exposing only a few exports from the main jotai bundle. They are split into four categories below.

atomuseAtomStoreProvider

Utilities

Jotai also includes a jotai/utils bundle with a variety of extra utility functions. One example is atomWithStorage, which includes localStorage persistence and browser tab synchronization.

StorageSSRAsyncResettableFamily

Integrations

Jotai has separate bundles for many official integrations including atomWithQuery for React Query and atomWithMachine for XState, among many others.

tRPCQueryURQLImmerXStateLocationCacheMoleculesOptics

Tools

There are also SWC and Babel compiler plugins for React Fast Refresh support and debugging labels to provide the best developer experience when using Jotai in a React framework such as Next.js or Gatsby.

SWCBabelDevtools

Basics

Learn the basic concepts and primitives of the library, discover how it compares with other solutions, and see examples of it in use.

ConceptsComparisonShowcase

Guides

These guides can help with use common cases such as TypeScript, React frameworks, and basic patterns.

v2 API migrationTypeScriptNext.jsGatsbyRemixReact NativeDebuggingPerformanceTestingCore internalsComposing atomsAtoms in atomInitializing state on renderPersistence

Recipes

These recipes can help with more advanced patterns.

Large objectsAtom creatorsCustom useAtom hooks