#Jotai
#使用 jotai
Jotai 采用“原子化”的方法来管理全局 React 状态。
#安装依赖
npm
yarn
pnpm
bun
deno
npm install jotaiyarn add jotaipnpm add jotaibun add jotaideno add npm:jotai#示例
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