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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-hook-form-ai

v1.0.10

Published

A wrapper package over React Hook Form that enables AI features like auto-fill and form summarization using the browser's built-in LLM.

Readme

npm downloads npm npm

A drop-in replacement for React Hook Form with AI-powered autofill and field suggestions. Supports Chrome Built-in AI, OpenAI, and custom AI providers with automatic fallback.

Features

  • 🤖 AI-Powered Autofill - Generate realistic form data using AI
  • 💡 Smart Field Suggestions - Get AI suggestions for individual fields
  • 🔄 Multiple Provider Support - Chrome Built-in AI, OpenAI, Custom Server, or Browser AI
  • 🛡️ Provider Fallback - Automatic fallback to next provider on failure
  • 📊 Download Progress - Monitor Chrome AI model download progress
  • Availability Checking - Check AI availability before use
  • 🌐 Global Configuration - Configure providers once with AIFormProvider
  • 📘 Full TypeScript Support - Complete type definitions included
  • 🔌 Drop-in Replacement - 100% compatible with React Hook Form API

Installation

npm install react-hook-form-ai
# or
pnpm add react-hook-form-ai
# or
yarn add react-hook-form-ai

Quick Start

import { useForm } from 'react-hook-form-ai';

interface FormData {
  firstName: string;
  lastName: string;
  email: string;
}

function App() {
  const {
    register,
    handleSubmit,
    aiAutofill,
    aiLoading,
    formState: { errors },
  } = useForm<FormData>();

  return (
    <form onSubmit={handleSubmit((data) => console.log(data))}>
      <input {...register('firstName')} placeholder="First Name" />
      <input {...register('lastName', { required: true })} placeholder="Last Name" />
      {errors.lastName && <p>Last name is required.</p>}
      <input {...register('email')} placeholder="Email" type="email" />
      
      <button 
        type="button" 
        onClick={() => aiAutofill()}
        disabled={aiLoading}
      >
        {aiLoading ? 'Filling...' : 'AI Autofill'}
      </button>
      
      <input type="submit" />
    </form>
  );
}

Global Configuration

Configure AI providers globally for your entire application:

import { AIFormProvider } from 'react-hook-form-ai';

function Root() {
  return (
    <AIFormProvider
      providers={[
        { type: 'chrome', priority: 10 },
        { 
          type: 'openai', 
          apiKey: process.env.REACT_APP_OPENAI_KEY || '',
          model: 'gpt-3.5-turbo',
          priority: 5 
        },
        {
          type: 'custom',
          apiUrl: 'https://your-api.com',
          priority: 1
        }
      ]}
      fallbackOnError={true}
    >
      <App />
    </AIFormProvider>
  );
}

Documentation

API & Examples

Resources

Key Concepts

AI Providers

React Hook Form AI supports multiple AI providers:

  • Chrome Built-in AI - Free, privacy-friendly, on-device AI (requires Chrome 127+)
  • OpenAI - Cloud-based AI using GPT models (requires API key)
  • Custom Server - Your own AI backend
  • Browser AI - Browser-based AI services

Provider Priority and Fallback

Providers are tried in order based on priority or execution order. When fallbackOnError is true, the next provider is automatically tried if one fails.

// Chrome AI → OpenAI → Custom Server
providers={[
  { type: 'chrome', priority: 10 },
  { type: 'openai', apiKey: 'sk-...', priority: 5 },
  { type: 'custom', apiUrl: 'https://api.example.com', priority: 1 }
]}

Security

Always exclude sensitive fields from AI processing:

const form = useForm({
  ai: {
    excludeFields: ['password', 'ssn', 'creditCard']
  }
});

Common Use Cases

Multi-Provider Setup

<AIFormProvider
  providers={[
    { type: 'chrome', priority: 10 },
    { type: 'openai', apiKey: 'sk-...', priority: 5 }
  ]}
  fallbackOnError={true}
>
  <App />
</AIFormProvider>

Field-Level Suggestions

const { aiSuggest, setValue } = useForm<FormData>();

const suggestion = await aiSuggest('email');
if (suggestion) {
  setValue('email', suggestion);
}

Chrome AI Download Handling

const { aiAvailability, aiDownloadProgress } = useForm();

if (aiAvailability?.needsDownload) {
  return <button onClick={() => aiAutofill()}>Download AI Model</button>;
}

if (aiAvailability?.status === 'downloading') {
  return <progress value={aiDownloadProgress || 0} max={100} />;
}

See Examples for more use cases.

API Overview

useForm Hook

const {
  // Standard React Hook Form properties
  register,
  handleSubmit,
  formState,
  // ... all other RHF properties
  
  // AI-specific properties
  aiEnabled,
  aiAutofill,
  aiSuggest,
  aiLoading,
  aiAvailability,
  refreshAvailability,
  aiDownloadProgress
} = useForm<FormData>({
  ai: {
    enabled: true,
    providers: [...],
    excludeFields: ['password']
  }
});

See API Reference for complete documentation.

Browser Compatibility

| Browser | Chrome AI | OpenAI | Custom Server | |---------|-----------|--------|---------------| | Chrome 127+ | ✅ | ✅ | ✅ | | Chrome <127 | ❌ | ✅ | ✅ | | Firefox | ❌ | ✅ | ✅ | | Safari | ❌ | ✅ | ✅ | | Edge | ❌ | ✅ | ✅ | | Mobile | ❌ | ✅ | ✅ |

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Credits

This library is built on top of React Hook Form. All credit for the core form management functionality goes to the React Hook Form team.

License

MIT © Saad Bazaz