@effect-atom/atom 一个用于 Effect 的反应式状态管理库。 安装 如果您使用的是 React: bash pnpm add @effect-atom/atom-reac…
@effect-atom/atom 一个用于 Effect 的反应式状态管理库。 安装 如果您使用的是 React: bash pnpm add @effect-atom/atom-reac…
一个用于 Effect 的反应式状态管理库。
如果您使用 React:
pnpm add @effect-atom/atom-react我们来创建一个简单的 Counter 组件,当您点击按钮时,它会增加一个数字。
我们将使用 Atom.make 来创建我们的 Atom,它是一个反应性状态容器。
然后,我们可以使用 useAtomValue 和 useAtomSet 钩子来读取和更新值
原子。
…您可以通过几种方式从原子中创建派生状态。
import { Atom } from "@effect-atom/atom-react"
const countAtom = Atom.make(0)
// You can use the `get` function to get the value of another Atom.
//
// The type of `get` is `Atom.Context`, which also has a bunch of other methods
// on it to manage Atoms.
//
const doubleCountAtom = Atom.make((get) => get(countAtom) * 2)
// You can also use the `Atom.map` function to create a derived Atom.
const tripleCountAtom = Atom.map(countAtom, (count) => count * 3)您还可以将效果传递给 Atom.make 函数。
在处理具有效果的 Atoms 时,您将获得 Result 类型的结果。
您可以在以下链接中查看如何使用 Result:https://tim-smart.github.io/effect-atom/atom/Result.ts.html
暂无开放 Issues,或尚未同步最近议题。