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

@philiprehberger/react-form-hooks

v0.1.7

Published

Lightweight form management hook with Zod validation, debounced field validation, and common validators

Downloads

546

Readme

@philiprehberger/react-form-hooks

CI npm version License

Lightweight form management hook with Zod validation

Installation

npm install @philiprehberger/react-form-hooks zod

Usage

import { useForm, validators } from '@philiprehberger/react-form-hooks';
import { z } from 'zod';

const schema = z.object({
  email: validators.email,
  password: validators.password,
});

function LoginForm() {
  const { errors, handleSubmit, getFieldProps } = useForm({
    schema,
    initialValues: { email: '', password: '' },
  });

  return (
    <form onSubmit={handleSubmit(async (values) => { await login(values); })}>
      <input {...getFieldProps('email')} />
      {errors.email && <span>{errors.email}</span>}

      <input type="password" {...getFieldProps('password')} />
      {errors.password && <span>{errors.password}</span>}

      <button type="submit">Log In</button>
    </form>
  );
}

Features

  • Zod schema validation with debounced field-level validation
  • getFieldProps() for easy input binding (handles checkbox, number, text)
  • Dirty tracking, touched state, submit handling
  • FormProvider / useFormContext for nested form components
  • Common validators: email, password, phone, name, address, URL, slug, etc

API

useForm(options)

| Option | Type | Default | Description | |--------|------|---------|-------------| | schema | z.ZodObject | -- | Zod schema for validation | | initialValues | z.infer<T> | -- | Initial form values | | validateOnChange | boolean | true | Validate on value change | | validateOnBlur | boolean | true | Validate on field blur | | debounceMs | number | 300 | Debounce delay for field validation | | onSubmitSuccess | () => void | -- | Callback after successful submit | | onSubmitError | (error: Error) => void | -- | Callback on submit error |

Return value

| Property | Type | Description | |----------|------|-------------| | values | z.infer<T> | Current form values | | errors | Record<string, string \| null> | Field error messages | | touched | Record<string, boolean> | Fields the user has interacted with | | isSubmitting | boolean | Whether the form is submitting | | isValid | boolean | Whether all fields pass validation | | isDirty | boolean | Whether any field differs from initial values | | setValue | (field, value) => void | Set a field value | | setTouched | (field) => void | Mark a field as touched | | setError | (field, error) => void | Manually set a field error | | validateField | (field) => Promise<string \| null> | Validate a single field | | validateForm | () => Promise<boolean> | Validate the entire form | | resetForm | () => void | Reset to initial values | | handleSubmit | (onSubmit) => (e) => void | Submit handler wrapper | | getFieldProps | (field) => object | Spread onto input elements for automatic binding | | getFieldState | (field) => object | Get value, error, touched, and dirty state for a field |

validators

Pre-built Zod validators: email, password, passwordSimple, phone, phoneRequired, name, nameOptional, price, quantity, url, urlRequired, slug, rating, date, futureDate, checkbox, checkboxRequired, textContent(min, max), address.

Utilities

| Function | Signature | Description | |----------|-----------|-------------| | makeOptional | (schema: z.ZodObject) => z.ZodObject | Make all fields in a schema optional | | pickFields | (schema: z.ZodObject, keys: string[]) => z.ZodObject | Pick specific fields from a schema | | FormProvider | ({ value, children }) => JSX.Element | Provide form state via React context | | useFormContext | () => FormContextValue | Access form state from a descendant component |

Development

npm install
npm run build
npm test

License

MIT