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

use-form-definition

v1.0.0

Published

A UI-agnostic React form library that generates forms from simple field definitions with Zod validation and React Hook Form integration

Readme

use-form-definition

A powerful, UI-agnostic React form library that generates type-safe forms from simple field definitions with Zod validation and React Hook Form integration.

Features

  • Definition-driven: Generate forms from simple field definitions
  • UI-agnostic: Works with any React component library
  • Type-safe: Full TypeScript support with automatic type inference
  • React 19 Compatible: Built-in support for server actions
  • Plugin Architecture: Extensible async validation and custom field types
  • Repeater Fields: Dynamic lists with recursive field definitions
  • Translation-ready: Pluggable i18n support
  • Copy-and-Customize: Own your components completely

Installation

npm install use-form-definition react react-hook-form zod

Requirements

  • React >= 18.0.0
  • React Hook Form >= 7.0.0
  • Zod >= 3.0.0 < 4.0.0

Quick Start

1. Configure your form hook

// lib/form.ts
import { createFormDefinitionHook } from 'use-form-definition';
import { Input, Select, Field } from '@/components/form';

export const useFormDefinition = createFormDefinitionHook({
  components: {
    text: Input,
    email: Input,
    select: Select,
  },
  formComponents: {
    Field: Field,
  },
});

2. Define your form

// forms/user.ts
import { FormDefinition } from 'use-form-definition';

export const userFormDefinition: FormDefinition = {
  name: {
    type: 'text',
    label: 'Name',
    validation: { required: true, minLength: 2 },
  },
  email: {
    type: 'email',
    label: 'Email',
    validation: { required: true },
  },
  role: {
    type: 'select',
    label: 'Role',
    options: [
      { value: 'admin', label: 'Admin' },
      { value: 'user', label: 'User' },
    ],
  },
};

3. Render your form

// components/UserForm.tsx
import { useFormDefinition } from '@/lib/form';
import { userFormDefinition } from '@/forms/user';

export function UserForm() {
  const { RenderedForm } = useFormDefinition(userFormDefinition);

  return <RenderedForm onSubmit={(data) => console.log(data)} />;
}

Copy-and-Customize Components

Use the CLI to copy reference components to your project:

# Copy all basic components
npx use-form-definition copy all ./src/components/form/

# Copy individual components
npx use-form-definition copy text-input ./src/components/
npx use-form-definition copy field ./src/components/

Documentation

Examples

See the examples directory for complete implementations:

| Example | Description | |---------|-------------| | basic-react | Core features with built-in unstyled components | | nextjs | Server actions, i18n, API routes | | mui | Material UI integration | | antd | Ant Design integration | | shadcn | shadcn/ui + Tailwind CSS |

Server Actions (Next.js)

// Server action
'use server';
import { generateDataValidator } from 'use-form-definition/server';

export async function createUser(prevState: any, formData: FormData) {
  const validator = generateDataValidator(userFormDefinition);
  const result = validator(formData);

  if (!result.success) {
    return { success: false, errors: result.errors };
  }

  // Process valid data...
  return { success: true, data: result.data };
}
// Client component
<RenderedForm
  action={createUser}
  onSuccess={(result) => console.log('Success:', result)}
/>

Validation

Built-in validation rules:

validation: {
  required: true,
  minLength: 2,
  maxLength: 100,
  pattern: 'email',        // Built-in patterns: email, url, phone, slug, username, etc.
  matchValue: 'password',  // Match another field
  requiredWhen: { field: 'type', value: 'other' },  // Conditional
  mustBeTrue: true,        // For checkboxes
  min: 0,
  max: 100,
}

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT