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

effectts-react

v0.7.0

Published

React hooks for Effect-TS

Readme

effectts-react

CI

React hooks for Effect-TS

Installation

npm install effectts-react
# or
yarn add effectts-react
# or
pnpm add effectts-react

Requirements

  • React 18+
  • Effect-TS 3+

Usage

useEffectQuery

Run an Effect and get its result in your React component:

import { useEffectQuery } from 'effectts-react';
import * as Effect from 'effect/Effect';

function MyComponent() {
  const { data, error, loading } = useEffectQuery(
    Effect.succeed('Hello, Effect!'),
    []
  );

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error}</div>;
  return <div>{data}</div>;
}

useRuntime

Create a runtime for running Effects:

import { useRuntime } from 'effectts-react';
import * as Effect from 'effect/Effect';

function MyComponent() {
  const runtime = useRuntime();

  const handleClick = () => {
    const effect = Effect.sync(() => console.log('Clicked!'));
    Effect.runPromise(effect);
  };

  return <button onClick={handleClick}>Click me</button>;
}

usePoll

Run an Effect repeatedly at a specified interval:

import { usePoll } from 'effectts-react';
import * as Effect from 'effect/Effect';

function MyComponent() {
  const { data, error, loading } = usePoll(
    Effect.sync(() => new Date().toISOString()),
    1000, // Run every 1 second
    []
  );

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error}</div>;
  return <div>Current time: {data}</div>;
}

useEffectRef

Manage mutable state with Effect Ref for safe concurrent access:

import { useEffectRef } from 'effectts-react';

function Counter() {
  const { value, loading, set, update } = useEffectRef(0);

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <p>Count: {value}</p>
      <button onClick={() => update(n => n + 1)}>Increment</button>
      <button onClick={() => update(n => n - 1)}>Decrement</button>
      <button onClick={() => set(0)}>Reset</button>
    </div>
  );
}

useSynchronizedRef

Perform atomic, effectful state updates with SynchronizedRef:

import { useSynchronizedRef } from 'effectts-react';
import * as Effect from 'effect/Effect';

function UserList() {
  const { value, loading, updateEffect } = useSynchronizedRef<string[]>([]);

  const fetchAndAddUser = async () => {
    await updateEffect(users =>
      Effect.gen(function* () {
        // Simulate fetching user data
        const response = yield* Effect.promise(() =>
          fetch('/api/user').then(r => r.json())
        );
        return [...users, response.name];
      })
    );
  };

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <button onClick={fetchAndAddUser}>Add User</button>
      <ul>
        {value?.map((user, i) => <li key={i}>{user}</li>)}
      </ul>
    </div>
  );
}

useSubscriptionRef

Reactive state management with automatic change notifications:

import { useSubscriptionRef } from 'effectts-react';

function ReactiveCounter() {
  const { value, loading, update } = useSubscriptionRef(0);

  // Value automatically updates when the ref changes
  if (loading) return <div>Loading...</div>;

  return (
    <div>
      <p>Count: {value}</p>
      <button onClick={() => update(n => n + 1)}>Increment</button>
    </div>
  );
}

API

useEffectQuery<A, E>(effect: Effect.Effect<A, E>, deps?: DependencyList)

Runs an Effect and returns its result.

Parameters:

  • effect: The Effect to run
  • deps: Dependency array (like React's useEffect)

Returns:

{
  data: A | null;
  error: E | null;
  loading: boolean;
}

useRuntime<R>(context?: Context.Context<R>)

Creates a runtime for running Effects.

Parameters:

  • context: Optional context to provide to the runtime

Returns: Runtime instance

usePoll<A, E>(effect: Effect.Effect<A, E>, intervalMs: number, deps?: DependencyList)

Runs an Effect repeatedly at a specified interval.

Parameters:

  • effect: The Effect to run
  • intervalMs: Interval in milliseconds
  • deps: Dependency array

Returns:

{
  data: A | null;
  error: E | null;
  loading: boolean;
}

useEffectRef<A>(initialValue: A)

Creates a mutable reference with Effect Ref for safe concurrent state management.

Parameters:

  • initialValue: The initial value for the Ref

Returns:

{
  value: A | null;
  loading: boolean;
  get: () => Promise<A>;
  set: (value: A) => Promise<void>;
  update: (f: (a: A) => A) => Promise<void>;
  modify: <B>(f: (a: A) => readonly [B, A]) => Promise<B>;
}

useSynchronizedRef<A>(initialValue: A)

Creates a SynchronizedRef for atomic, effectful state updates.

Parameters:

  • initialValue: The initial value for the SynchronizedRef

Returns:

{
  value: A | null;
  loading: boolean;
  get: () => Promise<A>;
  set: (value: A) => Promise<void>;
  update: (f: (a: A) => A) => Promise<void>;
  updateEffect: <R, E>(f: (a: A) => Effect.Effect<A, E, R>) => Promise<void>;
  modify: <B>(f: (a: A) => readonly [B, A]) => Promise<B>;
}

useSubscriptionRef<A>(initialValue: A)

Creates a SubscriptionRef with automatic change notifications via reactive streams.

Parameters:

  • initialValue: The initial value for the SubscriptionRef

Returns:

{
  value: A | null;
  loading: boolean;
  get: () => Promise<A>;
  set: (value: A) => Promise<void>;
  update: (f: (a: A) => A) => Promise<void>;
  updateEffect: <R, E>(f: (a: A) => Effect.Effect<A, E, R>) => Promise<void>;
  modify: <B>(f: (a: A) => readonly [B, A]) => Promise<B>;
}

Development

Running Tests

npm test
# or
make test

Type Checking

npm run typecheck
# or
make typecheck

Building

npm run build
# or
make build

Publishing

This project uses an Effect-TS pipeline for automated publishing. See PUBLISHING.md for details.

Quick publish commands:

# Publish a patch version (0.1.0 → 0.1.1)
make publish-patch

# Publish a minor version (0.1.0 → 0.2.0)
make publish-minor

# Publish a major version (0.1.0 → 1.0.0)
make publish-major

Test with dry-run mode:

npx tsx scripts/publish.ts patch --dry-run

License

MIT