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.
- π€ 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
npm install react-hook-form-ai
# or
pnpm add react-hook-form-ai
# or
yarn add react-hook-form-aiimport { 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>
);
}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>
);
}- π API Reference - Complete API documentation
- π» Examples - Practical usage examples
- π React Hook Form Documentation - Learn about the underlying form library
- π€ Chrome Built-in AI Documentation - Official Chrome AI documentation
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
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 }
]}Always exclude sensitive fields from AI processing:
const form = useForm({
ai: {
excludeFields: ['password', 'ssn', 'creditCard']
}
});<AIFormProvider
providers={[
{ type: 'chrome', priority: 10 },
{ type: 'openai', apiKey: 'sk-...', priority: 5 }
]}
fallbackOnError={true}
>
<App />
</AIFormProvider>const { aiSuggest, setValue } = useForm<FormData>();
const suggestion = await aiSuggest('email');
if (suggestion) {
setValue('email', suggestion);
}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.
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 | Chrome AI | OpenAI | Custom Server |
|---|---|---|---|
| Chrome 127+ | β | β | β |
| Chrome <127 | β | β | β |
| Firefox | β | β | β |
| Safari | β | β | β |
| Edge | β | β | β |
| Mobile | β | β | β |
We welcome contributions! Please see our Contributing Guide for details.
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.
MIT Β© Saad Bazaz