> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# Jotai

## 使用 `jotai`

[Jotai](https://jotai.org) 采用“原子化”的方法来管理全局 React 状态。

### 安装依赖


```sh [npm]
npm install jotai
```

```sh [yarn]
yarn add jotai
```

```sh [pnpm]
pnpm add jotai
```

```sh [bun]
bun add jotai
```

```sh [deno]
deno add npm:jotai
```

### 示例

```jsx
import { useEffect } from '@lynx-js/react';
import { atom, useAtom } from 'jotai';

const counter = atom(0);

export function App() {
  const [count, setCounter] = useAtom(counter);

  useEffect(() => {
    console.log('count changed:', count);
  }, [count]);

  return (
    <view>
      <text>{count}</text>
      <text bindtap={() => setCounter((prev) => prev + 1)}>Tap</text>
    </view>
  );
}
```

更多细节请参考 [Jotai - atom](https://jotai.org/docs/core/atom)
