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

@wunderwerk/easy-server-actions

v2.1.0

Published

Provides convenient functions for both server and client to create and consume React Server Actions!

Readme

@wunderwerk/easy-server-actions

Provides convenient functions for both server and client to create and consume React Server Actions!

Defining Server Actions

A Server Action can easily be created using the serverAction function. By using zod an optional schema can be passed to validate incoming data.

"use server";

import {
  ServerActionErr,
  ServerActionOk,
} from "@wunderwerk/easy-server-actions";
import { serverAction } from "@wunderwerk/easy-server-actions/server";
import { z } from "zod";

// Payload schema.
const schema = z.object({
  name: z.string(),
});

/**
 * Server Action with input data.
 */
export const myAction = serverAction(schema, async (input) => {
  const greeting = `Welcome ${input.name}!`

  // Run your server code here!

  // On error.
  if (false) {
    return ServerActionErr({
      code: "some_error",
      title: "Some Error",
      detail: "An error occured whilst running the server action",
    });
  }

  return ServerActionOk(greeting);
});

/**
 * Server Action without input data.
 */
export const myActionWithoutSchema = serverAction(async () => {
  // Run your server code here!

  return ServerActionOk({
    data: "some-data",
  });
});

The return value of the server action must be either ServerActionErr or ServerActionOk.

The ServerActionOk can contain any value, the signature of the error must match the predefined type.

Consuming Server Actions

This package provides integration with @tanstack/react-query to consume a server action.

Fetch data

Use a server action to just fetch data.

By using the useServerActionQuery react hook a server action can directly be consumed and used like using useQuery from @tanstack/react-query.

This hook supports all the options as useQuery.

More Info: TanStack Query useQuery Docs.

"use client";

import { useServerActionQuery } from "@wunderwerk/easy-server-actions/client";

import { myAction } from "../some-path";

export function MyComponent() {
    const { data, isLoading } = useServerActionQuery(myAction, {
        queryKey: ["some-key"],
    });

    return <div />;
}

Fetch paginated data

Similar to the hook above there is a custom variant for paginated data.

The useServerActionInfiniteQuery react hook provides integration with the useInfiniteQuery hook from @tanstack/react-query.

This hook supports all the options as useInfiniteQuery.

More Info: TanStack Query useInfiniteQuery Docs.

"use client";

import { useServerActionInfiniteQuery } from "@wunderwerk/easy-server-actions/client";

import { myAction } from "../some-path";

export function MyComponent() {
    const { data, isLoading } = useServerActionInfiniteQuery(myAction, {
        queryKey: ["some-key"],
        prepareQueryFn(pageParam) {
            // `pageParam` is the param coming from the `getNextPageParam` function.
            // See `useInfiniteQuery` docs from TanStack Query for more info.

            // Return the input object for the server action here.
            return {};
        },
    });

    return <div />;
}

Post data

Use a server action to post new data to the server.

The useServerAction react hook can be used to achieve that.

An array with a dispatch function and a loading boolean is returned from the hook, success and error callbacks can be directly registered in the hook options.

"use client";

import { useServerAction } from "@wunderwerk/easy-server-actions/client";

import { myAction } from "../some-path";

export function MyComponent() {
    const [dispatchAction, isPending] = useServerAction(myAction, {
        onSuccess(greeting) {
            alert(greeting);
        },
        onError(err) {
            console.err(err);
            alert(err.title);
        },
    });

    const handleClick = async () {
        const greeting = await dispatchAction({
            name: "John Doe",
            email: "[email protected]",
        });

        // You have access to the success value here.
        // Or you can skip the return value and just use
        // the `onSuccess` callback.
        // Similarily you can wrap the action call in a
        // try/catch to get the error, or just use the
        // `onError` callback.
    };

    return (
        <div>
            <button onClick={handleClick} disabled={isPending}>Dispatch</button>
        </div>
    );
}