Now that we have an Atom Runtime with access to UserService, we can create an Atom that fetches users’ data.
In atoms/user.ts, add the following code:
import { Effect } from "effect";
import { atomRuntime } from "@/atom-runtime";import { UserService } from "@/services/user-service";
// ============ Users Atom ============export const usersAtom = atomRuntime.atom( Effect.gen(function* () { return yield* UserService.getUsers(); }),);We call atomRuntime.atom() and pass it an Effect. Inside the Effect, we call UserService.getUsers() to fetch users’ data.
Because usersAtom runs an Effect, it’s called an effectful Atom — a term we’ll use throughout the course to refer to any Atom that runs an Effect.