百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

effect-atom

> 编程语言
开源

@effect-atom/atom 一个用于 Effect 的反应式状态管理库。 安装 如果您使用的是 React: bash pnpm add @effect-atom/atom-reac…

770 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

@effect-atom/atom 一个用于 Effect 的反应式状态管理库。 安装 如果您使用的是 React: bash pnpm add @effect-atom/atom-reac…

@effect-atom/atom

一个用于 Effect 的反应式状态管理库。

安装

如果您使用 React:

bash
pnpm add @effect-atom/atom-react

使用 Atom 创建计数器

我们来创建一个简单的 Counter 组件,当您点击按钮时,它会增加一个数字。 我们将使用 Atom.make 来创建我们的 Atom,它是一个反应性状态容器。 然后,我们可以使用 useAtomValue 和 useAtomSet 钩子来读取和更新值 原子。

…

衍生状态

您可以通过几种方式从原子中创建派生状态。

typescript
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· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言