npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-effect-hooks

v0.4.0

Published

Effect.ts integration for React – hooks and runtime mirroring useTransition, useActionState, useOptimistic, and more

Readme

react-effect-hooks

Effect.ts integration for React. This library provides React hooks that run your logic as Effect programs instead of raw Promises or ad hoc async code. You get typed errors, composition, and Scope-based cleanup while keeping the same mental model as React’s built-in hooks.

npm package: react-effect-hooks (the name react-effect-hooks is taken on npm). Install with bun add react-effect-hooks or npm i react-effect-hooks.


What this library does

  • Shared runtime: A React context supplies a single Effect runtime. Your app (or a subtree) wraps with <EffectRuntimeProvider>. All hooks use that runtime to run or fork Effects. You configure Layers/Services and resource lifecycle in one place.
  • Explicit async state: Async hooks expose a small state machine: Idle, Pending, Success, Failure. Success and failure carry typed values and errors (E), so you avoid overloading a single error slot with unknown.
  • Scope-based cleanup: When a hook runs an Effect that should be cancellable (e.g. useRunEffect), it allocates a Scope, runs the Effect in that Scope, and closes the Scope on unmount or when dependencies change. That gives you the same cleanup semantics as in pure Effect code (interruption, finalizers).
  • API aligned with React: Hooks mirror React’s built-in hooks (including React 19–style patterns). The async/effectful part is expressed as an Effect; the hook shapes stay familiar.

Limited scope

This library is not a full “Effect-first” React framework. It does not:

  • Replace or reimplement React’s data flow, Suspense, or Server Components.
  • Provide Effect-based routing, data fetching, or form libraries.
  • Change how you structure your React tree or component hierarchy.

It only:

  • Lets you run Effect programs from React hooks via a shared runtime.
  • Provides hook variants that mirror useTransition, useActionState, useOptimistic, useEffect, useState, and useReducer, with the async/effectful part implemented as Effects and with typed errors and Scope cleanup where applicable.

Use it when you already use Effect and want consistent Effect semantics (errors, resources, cancellation) at the React boundary. If you don’t use Effect, this library is not for you.


When it’s useful

  • You use Effect elsewhere (services, layers, typed errors) and want the same runtime and semantics in React (e.g. in event handlers, transitions, or effects).
  • You want typed errors and explicit Idle/Pending/Success/Failure state in async hooks instead of overloading error: unknown.
  • You want Scope-based cleanup (interruption, finalizers) for Effects started from hooks, instead of ad hoc AbortController or manual cleanup.
  • You prefer hook APIs that mirror React’s useTransition, useActionState, useOptimistic, etc., so the learning curve is small.

Hooks

| React hook | react-effect-hooks hook | Notes | |-------------------|-----------------------------|--------| | useTransition | useTransitionEffect | [isPending, startTransition]; startTransition runs an Effect. | | useActionState | useActionStateEffect | [state, dispatchAction, isPending]; the action is an Effect; state/error/isPending from last run. | | useOptimistic | useOptimisticEffect | [optimisticState, setOptimistic]; commit runs an Effect; on success commit, on failure revert. | | useEffect | useRunEffect | (effect, deps); runs the Effect in a Scope; Scope is closed on cleanup. | | useState | useEffectState | Setter accepts a value, an updater function, or an Effect; when an Effect is passed, it’s run and result/error drive state. | | useReducer | useEffectReducer | Reducer returns Effect<NextState, E, R>; dispatch runs that Effect and updates state from the result. |

Async state is represented as: { _tag: 'idle' } | { _tag: 'pending' } | { _tag: 'success', value: A } | { _tag: 'failure', error: E }. Helpers: idle, pending, success, failure, isIdle, isPending, isSuccess, isFailure (from AsyncState).


Usage

  1. Wrap your app (or the subtree that uses these hooks) with <EffectRuntimeProvider>. Optionally pass a custom Runtime<R> (e.g. built from Layers).
  2. Use the hooks inside that tree. For hooks that require services R, build the provider’s runtime with the right Layers so Effect<A, E, R> can be run.

No React 19 requirement; the API is designed so that when you move to React 19, the same patterns align with the built-in hooks.


Design (summary)

  • Runtime: One shared runtime from context; hooks submit Effects to it. Single place for Layers/Services and resource lifecycle.
  • Cleanup: Scope is used for cancellable runs; closing the Scope on unmount/deps change interrupts fibers and runs finalizers.
  • API: Hook names and signatures stay close to React’s; the only difference is that the async/effectful part is an Effect.

File layout

  • AsyncState.tsAsyncState<A, E> and helpers.
  • EffectRuntime.tsx – Context, EffectRuntimeProvider, useEffectRuntime.
  • useRunEffect.ts, useTransitionEffect.ts, useActionStateEffect.ts, useOptimisticEffect.ts, useEffectState.ts, useEffectReducer.ts – hook implementations.
  • index.ts – re-exports.

Dependencies

  • effect – Effect core (Runtime, Scope, Effect, Fiber, etc.).
  • react – context, hooks, types.

Peer dependencies: effect >= 3.0.0, react >= 18.0.0.