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

@devup-api/hookform

v0.1.8

Published

Type-safe form components for devup-api with react-hook-form integration and automatic Zod validation.

Readme

@devup-api/hookform

Type-safe form components for devup-api with react-hook-form integration and automatic Zod validation.

Installation

npm install @devup-api/hookform @devup-api/fetch react-hook-form zod

Features

  • Automatic Zod Validation: Uses Zod schemas generated from your OpenAPI spec
  • FormProvider Integration: Children can access form context via useFormContext
  • Type-Safe: Full TypeScript support with inferred types from OpenAPI
  • Easy API Submission: Handles form submission to your API endpoints automatically

Usage

Basic Setup

import { createApi } from '@devup-api/fetch'
import { ApiForm, useFormContext } from '@devup-api/hookform'

const api = createApi('https://api.example.com')

// Form fields component using form context
function FormFields() {
  const { register, formState: { errors, isSubmitting } } = useFormContext()
  
  return (
    <>
      <input {...register('name')} placeholder="Name" />
      {errors.name && <span>{errors.name.message}</span>}
      
      <input {...register('email')} placeholder="Email" type="email" />
      {errors.email && <span>{errors.email.message}</span>}
      
      <button type="submit" disabled={isSubmitting}>
        {isSubmitting ? 'Submitting...' : 'Submit'}
      </button>
    </>
  )
}

// Main form component
function CreateUserForm() {
  return (
    <ApiForm
      api={api}
      method="post"
      path="createUser"  // operationId or path like '/users'
      onSuccess={(data) => {
        console.log('User created:', data)
      }}
      onError={(error) => {
        console.error('Failed:', error)
      }}
    >
      <FormFields />
    </ApiForm>
  )
}

With Default Values

<ApiForm
  api={api}
  method="put"
  path="/users/{id}"
  requestOptions={{ params: { id: '123' } }}
  defaultValues={{
    name: 'John Doe',
    email: '[email protected]'
  }}
  onSuccess={(data) => console.log('Updated:', data)}
>
  <FormFields />
</ApiForm>

With Validation Mode

<ApiForm
  api={api}
  method="post"
  path="createUser"
  mode="onChange"  // Validate on every change
  onValidationError={(errors) => {
    console.log('Validation failed:', errors)
  }}
  onSuccess={(data) => console.log('Created:', data)}
>
  <FormFields />
</ApiForm>

Reset Form After Success

<ApiForm
  api={api}
  method="post"
  path="createUser"
  resetOnSuccess={true}
  onSuccess={(data) => console.log('Created:', data)}
>
  <FormFields />
</ApiForm>

Custom Form Props

<ApiForm
  api={api}
  method="post"
  path="createUser"
  formProps={{
    className: 'my-form',
    id: 'create-user-form'
  }}
  onSuccess={(data) => console.log('Created:', data)}
>
  <FormFields />
</ApiForm>

Props

| Prop | Type | Description | |------|------|-------------| | api | DevupApi | The API client instance from @devup-api/fetch | | method | 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method for form submission | | path | string | API path or operationId | | openapi | string | Server name for multi-server setups (default: 'openapi.json') | | requestOptions | object | Additional request options (params, query, headers) | | onSuccess | (data) => void | Called when API request succeeds | | onError | (error) => void | Called when API request fails | | onValidationError | (errors) => void | Called when form validation fails | | children | ReactNode | Form content | | defaultValues | object | Default values for form fields | | mode | 'onSubmit' \| 'onBlur' \| 'onChange' \| 'onTouched' \| 'all' | Validation mode (default: 'onSubmit') | | formOptions | UseFormProps | Additional react-hook-form options | | formProps | FormHTMLAttributes | HTML form element props | | resetOnSuccess | boolean | Reset form after successful submission (default: false) |

Form Context

Children components can access form context using react-hook-form's useFormContext:

import { useFormContext } from '@devup-api/hookform'

function FormField({ name }: { name: string }) {
  const { register, formState: { errors } } = useFormContext()
  
  return (
    <div>
      <input {...register(name)} />
      {errors[name] && <span>{errors[name].message}</span>}
    </div>
  )
}

How Validation Works

The ApiForm component automatically uses Zod schemas generated from your OpenAPI spec:

  1. When you specify a path and method, the component looks up the corresponding request body schema
  2. The schema is used with @hookform/resolvers/zod for validation
  3. Form submission is blocked if validation fails
  4. If no schema is found, the form submits without validation

Type Safety

All props are fully typed based on your OpenAPI schema:

  • path is typed to only accept valid paths for the specified method
  • requestOptions types match the endpoint's params/query/headers
  • onSuccess receives the typed response data
  • onError receives the typed error response
  • defaultValues must match the request body schema

Re-exported from react-hook-form

For convenience, the following are re-exported from react-hook-form:

  • useFormContext
  • useWatch
  • useFieldArray
  • useController
  • Controller

License

Apache 2.0