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-action-z

v0.0.19

Published

Turn async functions into UI actions. Handle loading, error, retry, and concurrency automatically.

Readme

⚡ react-action-z

NPM Downloads

LIVE EXAMPLE

Unified async action layer for React.

Run async functions as actions, not boilerplate. Actions run only when you call run() — never automatically.


Why react-action-z?

  • ⚡ Unified async actions
  • 🧠 Built-in loading / error state
  • 🔁 Retry support
  • 🧩 Middleware system
  • 🌍 Global action state
  • 🧾 Full TypeScript support

Traditional async UI code:

const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)

async function login(data) {
  try {
    setLoading(true)
    const result = await api.login(data)
  } catch (err) {
    setError(err)
  } finally {
    setLoading(false)
  }
}

React Action:

const login = useAction(api.login)

await login.run(data)

UI state automatically available:

login.loading
login.data
login.error

Installation

npm install react-action-z

Basic Usage

import { useAction } from "react-action-z"

const login = useAction(api.login)

await login.run({
  email,
  password
})

State is automatically managed:

login.loading
login.data
login.error

UI example:

<button disabled={login.loading}>
  {login.loading ? "Loading..." : "Login"}
</button>

Example with JSONPlaceholder

Example using the free API from JSONPlaceholder.

Fetch a user from:

https://jsonplaceholder.typicode.com/users/1

API

async function fetchUser(id: number) {
  const res = await fetch(
    `https://jsonplaceholder.typicode.com/users/${id}`
  )

  if (!res.ok) {
    throw new Error("Failed to fetch user")
  }

  return res.json()
}

React Component

import React from "react"
import { useAction } from "react-action-z"

async function fetchUser(id: number) {
  const res = await fetch(
    `https://jsonplaceholder.typicode.com/users/${id}`
  )

  if (!res.ok) {
    throw new Error("Failed to fetch user")
  }

  return res.json()
}

export default function UserExample() {

  const getUser = useAction(fetchUser)

  return (
    <div>

      <button
        onClick={() => getUser.run(1)}
        disabled={getUser.loading}
      >
        {getUser.loading ? "Loading..." : "Load User"}
      </button>

      {getUser.error && (
        <p>Error loading user</p>
      )}

      {getUser.data && (
        <div style={{ marginTop: 20 }}>
          <h3>{getUser.data.name}</h3>
          <p>{getUser.data.email}</p>
          <p>{getUser.data.phone}</p>
        </div>
      )}

    </div>
  )
}

Result

Click the button:

Load User

The action automatically manages:

loading
data
error

Example returned data:

{
  "id": 1,
  "name": "Leanne Graham",
  "username": "Bret",
  "email": "[email protected]",
  "phone": "1-770-736-8031"
}

Action API

const action = useAction(fn, options)

Return value:

action.run(...)
action.loading
action.data
action.error
action.reset()

Options

useAction(api.login, {
  retry: 2,
  strategy: "replace",
  key: "login",
  optimistic: (data) => {},
  onSuccess: (data) => {},
  onError: (err) => {}
})

| option | description | |-------------|---------------------| | retry | retry on failure | | strategy | concurrency control | | key | global action key | | optimistic | optimistic update | | onSuccess | success callback | | onError | error callback |


Concurrency Strategy

useAction(api.save, {
  strategy: "ignore"
})

| strategy | behavior | |----------|-----------------------------------| | replace | only latest result updates state | | ignore | ignore if running | | parallel | allow multiple runs |

Example:

const save = useAction(api.save, {
  strategy: "ignore"
})

Prevent double submit.


Retry

Automatically retry failed requests.

const fetchUser = useAction(api.fetchUser, {
  retry: 2
})

Behavior:

attempt 1
attempt 2
attempt 3

Optimistic Update

Apply UI update before request finishes.

const updateUser = useAction(api.updateUser, {
  optimistic: (data) => {
    setUser(data)
  }
})

This improves UI responsiveness.


Global Action State

Actions can share state across components.

import { useAction } from "react-action-z"

const login = useAction(api.login, {
  key: "login"
})

export function LoginButton() {
  return (
    <button
      disabled={login.loading}
      onClick={() => login.run({ email, password })}
    >
      {login.loading ? "Logging in..." : "Login"}
    </button>
  )
}

Access anywhere:

// GlobalSpinner.tsx

import { useGlobalAction } from "react-action-z"

export function GlobalSpinner() {

  const login = useGlobalAction("login")

  if (!login.loading) return null

  return <div>Authenticating...</div>
}

Result:

  • LoginButton triggers action
  • GlobalSpinner reacts automatically

Middleware

React Action supports middleware similar to Redux.

import { createActionClient } from "react-action-z"

createActionClient({
  middleware: [
    async (context, next) => {
      console.log("action:", context.key)
      return next()
    }
  ]
})

Middleware context:

{
  key?: string
  args: any[]
}

Use cases:

  • logging
  • analytics
  • metrics
  • debugging

Reset State

Reset action state manually.

login.reset()

Result:

{
  loading: false
  data: null
  error: null
}

Example

const createPost = useAction(api.createPost, {
  retry: 1
})

async function handleSubmit(data) {
  await createPost.run(data)
}

UI:

<button disabled={createPost.loading}>
  Publish
</button>

{createPost.error && <p>Error</p>}

Comparison

| Criteria | react-action-z | React state | |---------------------|----------------|-------------| | Async state | ✅ | manual | | Retry | ✅ | manual | | Global action state | ✅ | ❌ | | Middleware | ✅ | ❌ | | Optimistic update | ✅ | manual | | Boilerplate | minimal | high |


Architecture

Component
    ↓
useAction()
    ↓
Action Runner
    ↓
Middleware
    ↓
Async Function
    ↓
State Update

Philosophy

React Action treats async functions as first-class UI actions.

Instead of manually managing:

  • loading
  • error
  • retries
  • concurrency

You simply run actions:

action.run()

License

MIT