Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

effect-atom

> 编程语言
Open source

@effect-atom/atom A reactive state management library for Effect. Installation If you are using React: bash pnpm add @effect-atom/atom-reac…

770 stars0 likes3 views
WebsiteGitHub

About

@effect-atom/atom A reactive state management library for Effect. Installation If you are using React: bash pnpm add @effect-atom/atom-reac…

@effect-atom/atom

A reactive state management library for Effect.

Installation

If you are using React:

bash
pnpm add @effect-atom/atom-react

Creating a Counter with Atom

Let's create a simple Counter component, which will increment a number when you click a button.

We will use Atom.make to create our Atom, which is a reactive state container.

We can then use the useAtomValue & useAtomSet hooks to read and update the value of the Atom.

…

Derived State

You can create derived state from an Atom in a couple of ways.

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)

Working with Effects

You can also pass effects to the Atom.make function.

When working with effectful Atoms, you will get back a Result type.

You can see all the ways to work with Result here: https://tim-smart.github.io/effect-atom/atom/Result.ts.html

typescript
import { Atom, Result } from "@effect-atom/atom-react"
import { Effect } from "effect"

//        ┌─── Atom.Atom>
//        ▼
const countAtom = Atom.make(Effect.succeed(0))

// You can also pass a function to get access to the `Atom.Context`
//
// `get.result` can be used in `Effect`s to get the value of an `Atom.Atom`.
//
//             ┌─── Atom.Atom>
//             ▼
const resultWithContextAtom = Atom.make(
  Effect.fnUntraced(function* (get: Atom.Context) {
    const count = yield* get.result(countAtom)
    return count + 1
  }),
)

Working with scoped Effects

All Atoms that use effects are provided with a Scope, so you can add finalizers that will be run when the Atom is no longer used.

typescript
import { Atom } from "@effect-atom/atom-react"
import { Effect } from "effect"

const resultAtom = Atom.make(
  Effect.gen(function* () {
    // Add a finalizer to the `Scope` for this Atom
    // It will run when the Atom is rebuilt or no longer needed
    yield* Effect.addFinalizer(() => Effect.log("finalizer"))
    return "hello"
  }),
)

Working with Effect Services / Layers

…

Adding global Layers to AtomRuntimes

This is useful for setting up Tracers, Loggers, ConfigProviders, etc.

typescript
import { Atom } from "@effect-atom/atom-react"
import { ConfigProvider, Layer } from "effect"

Atom.runtime.addGlobalLayer(
  Layer.setConfigProvider(ConfigProvider.fromJson(import.meta.env)),
)

Working with Streams

…

Working with sets of Atoms

…

Working with functions

…

Wrapping an event listener

…

Integration with search params

typescript
import { Atom } from "@effect-atom/atom-react"
import { Option, Schema } from "effect"

// Create an Atom that reads and writes to the URL search parameters.
//
//          ┌─── Atom.Writable
//          ▼
const simpleParamAtom = Atom.searchParam("paramName")

// You can also use a schema to further parse the value
//
//          ┌─── Atom.Writable>
//          ▼
const numberParamAtom = Atom.searchParam("paramName", {
  schema: Schema.NumberFromString,
})

Integration with local storage

typescript
import { Atom } from "@effect-atom/atom-react"
import { BrowserKeyValueStore } from "@effect/platform-browser"
import { Schema } from "effect"

const runtime = Atom.runtime(BrowserKeyValueStore.layerLocalStorage)

// Create an Atom that reads and writes to `localStorage`.
//
// It uses `Schema` to define the type of the value stored.
//
//       ┌─── Atom.Writable
//       ▼
const flagAtom = Atom.kvs({
  runtime: runtime,
  key: "flag",
  schema: Schema.Boolean,
  defaultValue: () => false,
})

Integration with Reactivity from @effect/experimental

Reactivity is an Effect service that allows you make queries reactive when mutations happen.

You can use an Atom.runtime to hook into the Reactivity service and trigger Atom refreshes when mutations happen.

…

@effect/rpc integration

You can use the AtomRpc module to create an RPC client with integration with effect-atom. It offers apis for both queries and mutations.

…

HttpApi integration

You can use the AtomHttpApi module to create an HTTP API client with integration with effect-atom. It offers apis for both queries and mutations.

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

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