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

@heapform/react

v0.0.1

Published

Headless React helpers for submitting forms to Heapform.

Readme

@heapform/react

Headless React helpers for submitting forms to Heapform.

Basic usage

import { HeapformValidationError, useHeapform } from "@heapform/react";

export function ContactForm() {
  const [state, handleSubmit, reset] = useHeapform("contact");

  if (state.succeeded) {
    return (
      <div>
        <p>Thanks for your message.</p>
        <button type="button" onClick={reset}>
          Send another
        </button>
      </div>
    );
  }

  return (
    <form onSubmit={handleSubmit}>
      <label htmlFor="email">Email</label>
      <input id="email" name="email" type="email" required />
      <HeapformValidationError field="email" errors={state.errors} prefix="Email" />

      <label htmlFor="message">Message</label>
      <textarea id="message" name="message" required />
      <HeapformValidationError field="message" errors={state.errors} />

      <HeapformValidationError errors={state.errors} />

      <button disabled={state.submitting} type="submit">
        {state.submitting ? "Sending..." : "Send"}
      </button>
    </form>
  );
}

State object

useHeapform returns [state, handleSubmit, reset]:

| Key | Description | | --- | --- | | state.submitting | Whether a submission is in flight | | state.succeeded | Whether the last submission succeeded | | state.errors | A HeapformSubmissionError instance, or null | | state.result | Success metadata such as returnUrl, or null |

HeapformSubmissionError exposes:

  • getFormErrors() for form-level errors
  • getFieldErrors(field) for a single field
  • getAllFieldErrors() for all field errors

React Hook Form

Use useSubmit when another form library owns validation state:

import { useSubmit } from "@heapform/react";
import { useForm } from "react-hook-form";

type Inputs = {
  email: string;
  message: string;
};

export function ContactForm() {
  const { formState, handleSubmit, register, setError } = useForm<Inputs>();
  const submit = useSubmit<Inputs>("contact", {
    onError(errors) {
      for (const [field, fieldErrors] of errors.getAllFieldErrors()) {
        setError(field as keyof Inputs, {
          message: fieldErrors.map((error) => error.message).join(", "),
        });
      }

      for (const { code, message } of errors.getFormErrors()) {
        setError("root", { type: code, message });
      }
    },
  });

  return (
    <form onSubmit={handleSubmit(submit)}>
      <input {...register("email")} type="email" />
      <textarea {...register("message")} />
      <button disabled={formState.isSubmitting} type="submit">
        Send
      </button>
    </form>
  );
}

Next.js App Router

Next.js helpers live behind an optional subpath export so the root package stays framework-neutral:

import {
  getHeapformActionErrors,
  initialHeapformActionState,
  submitHeapformAction,
  type HeapformActionState,
} from "@heapform/react/next";

Use submitHeapformAction inside your own Server Action:

// app/contact/actions.ts
"use server";

import {
  submitHeapformAction,
  type HeapformActionState,
} from "@heapform/react/next";

export async function contactAction(
  _previousState: HeapformActionState,
  formData: FormData,
) {
  return submitHeapformAction("contact", formData);
}

Then wire it to useActionState:

// app/contact/form.tsx
"use client";

import { useActionState } from "react";
import { HeapformValidationError } from "@heapform/react";
import {
  getHeapformActionErrors,
  initialHeapformActionState,
} from "@heapform/react/next";
import { contactAction } from "./actions";

export function ContactForm() {
  const [state, formAction, isPending] = useActionState(
    contactAction,
    initialHeapformActionState,
  );
  const errors = getHeapformActionErrors(state);

  if (state.succeeded) {
    return <p>Thanks for your message.</p>;
  }

  return (
    <form action={formAction}>
      <input name="email" type="email" required />
      <HeapformValidationError field="email" errors={errors} prefix="Email" />
      <textarea name="message" required />
      <HeapformValidationError errors={errors} />
      <button disabled={isPending} type="submit">
        Send
      </button>
    </form>
  );
}

For a Server Component form that does not need client-side action state:

import { submitHeapformAction } from "@heapform/react/next";

export function ContactForm() {
  async function action(formData: FormData) {
    "use server";

    await submitHeapformAction("contact", formData);
  }

  return (
    <form action={action}>
      <input name="email" type="email" required />
      <button type="submit">Send</button>
    </form>
  );
}