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

@vanya2h/form-factory

v0.7.0

Published

Headless schema-driven form factory built on react-hook-form + zod.

Readme

@vanya2h/form-factory

Headless schema-driven form factory built on react-hook-form + zod.

Logic-only — no DOM, no styling, no built-in error UI, no submit button. Bring your own components.

Why

Most form libraries either bundle UI (and you fight them) or are so low-level that every form becomes copy-paste. This package extracts the bits that don't care about your design system:

  • A factory pattern for declaring schema + getDefaultData once and reusing it with different submitFn / seed / onResult per call site
  • An async seed (RxJS Observable) so forms can defer mounting until upstream data is ready
  • A submit pipeline that swallows p-cancelable CancelError, surfaces other errors as root form errors, and runs onResult on success

You provide the layout, the inputs, the buttons, the error display.

Install

pnpm add @vanya2h/form-factory react-hook-form rxjs zod

Peer deps: react ^18 || ^19, react-hook-form ^7, rxjs ^7, zod ^4.

Usage

import { z } from "zod";
import { of } from "rxjs";
import { createFormFactory, Form, useSubmitState, useFormSeed } from "@vanya2h/form-factory";

const schema = z.object({ email: z.string().email() });

const factory = createFormFactory({
  schema,
  getDefaultData: (_seed: { userId: string }) => ({ email: "" }),
});

function MyForm({ userId }: { userId: string }) {
  const seed$ = useFormSeed({ userId });

  const instance = factory.build({
    seed$,
    submitFn: async (value, seed) => {
      await api.updateEmail(seed.userId, value.email);
    },
    onResult: () => toast("Saved!"),
  });

  return (
    <Form instance={instance} pending={<Spinner />}>
      {({ form, handleSubmit, rootError }) => (
        <form onSubmit={handleSubmit}>
          <input {...form.register("email")} />
          {rootError && <p>{rootError.message}</p>}
          <SubmitButton />
        </form>
      )}
    </Form>
  );
}

function SubmitButton() {
  const { disabled } = useSubmitState();
  return (
    <button type="submit" disabled={disabled}>
      Save
    </button>
  );
}

API

createFormFactory({ schema, getDefaultData })

Returns a reusable factory bound to a zod schema and a default-data function.

  • factory.build({ seed$, submitFn, onResult?, ...rhfProps }) — returns an IFormInstance you pass to <Form> or useFormFactory.
  • factory.createSubmitFn(fn) — type helper that infers (value, seed) from the schema.

createFormStubFactory<TSeed>()

An empty-schema factory, useful for purely action-driven flows.

useFormSeed(default)

Returns a stable BehaviorSubject seeded with default. Push new seeds with .next(...) and the form re-renders.

<Form instance={...}>{...}</Form>

Subscribes to instance.seed$, wires useFormFactory, and provides FormProvider context. No DOM is rendered — only the render prop.

Render-prop receives { form, seed, instance, handleSubmit, rootError }.

Optional: pending / rejected for the seed-observable lifecycle.

useFormFactory({ instance, seed, onResult?, parseErrorMessage? })

The hook behind <Form>. Use directly when you've already resolved the seed.

parseErrorMessage(err) — customize how thrown submit errors are stringified into the root form error. Defaults to error.message ?? String(error).

useSubmitState()

Reads the nearest FormProvider to return { isSubmitting, isValidating, disabled } for your submit button.

useObservableValue(observable$)

Subscribes and returns { status: "pending" | "fulfilled" | "rejected", ... }. Synchronous emissions (e.g. BehaviorSubject) resolve to "fulfilled" on first render — no flicker.