formik-migrate
v0.2.0
Published
Smart Formik to React Hook Form migration - analyze, convert, and validate automatically
Maintainers
Readme
formik-migrate
The smart way to migrate from Formik to React Hook Form.
Analyze your codebase, auto-convert simple patterns, and get a clear migration plan for everything else.
Features
- Analyze your codebase and find all Formik usage
- Auto-convert simple patterns (~80% of code)
- Watch mode - re-analyze on file changes
- HTML reports - visual migration dashboard
- Zod support - convert Yup schemas to Zod (experimental)
- GitHub Action - block PRs that add new Formik code
- Safe - only converts what it understands
Why Migrate from Formik?
Formik is unmaintained - last update was over 2 years ago.
React Hook Form is the future - better performance, active maintenance, 9M weekly downloads.
But manual migration is painful and takes days or weeks for large codebases.
That's where formik-migrate helps.
What It Does
✅ Analyzes your codebase - finds all Formik usage
✅ Auto-converts simple patterns (~80% of code)
✅ Flags complex cases that need manual review
✅ Shows time/cost savings
✅ Safe - only converts what it understands
Quick Start
1. Install
npx formik-migrate analyzeNo installation needed! Use with npx.
Or install globally:
npm install -g formik-migrate2. Analyze Your Codebase
formik-migrate analyzeThis scans your project and shows:
- How many files use Formik
- What can be auto-converted
- What needs manual review
- Time/cost estimates
3. Convert Simple Patterns
formik-migrate convert --backupThis:
- Auto-converts simple
useFormik→useForm - Transforms simple
<Field>→ native<input> - Creates backups of original files
- Flags complex patterns for you to review
Example Output
╔══════════════════════════════════════════════════════════════╗
║ Formik → React Hook Form Migration Analysis ║
╚══════════════════════════════════════════════════════════════╝
📊 Summary:
• Total Files: 156
• Files Using Formik: 23
• Auto-Convertible: 18 ✓
• Manual Review: 5 ⚠️
⏱️ Time Estimates:
Manual migration: 12.5 hours
With formik-migrate: 3.2 hours
Time saved: 9.3 hours
💰 ROI (@ $100/hr):
Manual cost: $1,250
Savings: $930What Gets Auto-Converted
✅ Simple useFormik
Before:
import { useFormik } from 'formik';
const formik = useFormik({
initialValues: { email: '', password: '' },
validationSchema: loginSchema,
onSubmit: (values) => { /* ... */ },
});After:
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
const form = useForm({
defaultValues: { email: '', password: '' },
resolver: yupResolver(loginSchema),
});✅ Simple Fields
Before:
<Field name="email" type="email" />After:
<input {...register("email")} type="email" />What Needs Manual Review
⚠️ Complex Validation
// Custom validate function
validate: (values) => { /* complex logic */ }Solution: Convert to Zod or Yup schema
⚠️ Custom Field Components
<Field name="email" component={CustomInput} />Solution: Use Controller from React Hook Form
⚠️ Field Arrays with Complex Logic
<FieldArray name="items" render={({ push, remove }) => (
// Complex nested logic
)} />Solution: Use useFieldArray hook
CLI Commands
analyze [directory]
Analyze Formik usage in your codebase.
# Analyze current directory
formik-migrate analyze
# Analyze specific directory
formik-migrate analyze ./src
# Save report to file
formik-migrate analyze --output report.md
# JSON output
formik-migrate analyze --format jsonOptions:
-f, --format <format>- Output format (console, json, markdown, html)-o, --output <file>- Save report to file-w, --watch- Watch mode - re-analyze on file changes--html <file>- Generate HTML report
convert [directory]
Convert Formik code to React Hook Form.
# Preview changes (dry run)
formik-migrate convert --dry-run
# Convert with backups
formik-migrate convert --backup
# Convert without confirmation
formik-migrate convert --yesOptions:
-d, --dry-run- Preview without modifying files-b, --backup- Create.backupfiles-y, --yes- Skip confirmation prompts--zod- Convert Yup schemas to Zod (experimental)
stats [directory]
Quick summary of Formik usage.
formik-migrate statsWatch Mode
Re-analyze automatically when files change:
formik-migrate analyze --watchGreat for monitoring migration progress during development.
HTML Reports
Generate an interactive HTML dashboard:
formik-migrate analyze --html report.htmlThe report shows:
- Migration progress visualization
- Pattern breakdown (useFormik, Field, FieldArray, etc.)
- File-by-file status
- Time estimates
Zod Support (Experimental)
Convert Yup validation schemas to Zod:
formik-migrate convert --zod --backupYup:
Yup.object({
email: Yup.string().email().required(),
age: Yup.number().min(18).required(),
})Converted to Zod:
z.object({
email: z.string().email(),
age: z.number().min(18),
})Note: Complex validation patterns may need manual adjustment.
GitHub Action
Block PRs that add new Formik code:
# .github/workflows/formik-check.yml
name: Check Formik Usage
on: [pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: willzhangfly/formik-migrate@v1
with:
fail-on-formik: false # Fail if ANY Formik found
max-formik-files: 10 # Fail if more than 10 files use Formik
comment-on-pr: true # Add analysis comment to PRInputs:
| Input | Default | Description |
|-------|---------|-------------|
| path | . | Project directory |
| fail-on-formik | false | Fail if any Formik usage |
| max-formik-files | 0 | Max files with Formik (0 = no limit) |
| comment-on-pr | true | Add comment to PR |
Outputs:
formik-files- Number of files using Formikauto-convertible- Patterns that can be auto-convertedmanual-review- Patterns needing manual review
Real-World Example
Before Migration
import { useFormik } from 'formik';
import * as Yup from 'yup';
const LoginForm = () => {
const formik = useFormik({
initialValues: {
email: '',
password: '',
},
validationSchema: Yup.object({
email: Yup.string().email().required(),
password: Yup.string().min(8).required(),
}),
onSubmit: async (values) => {
await login(values);
},
});
return (
<form onSubmit={formik.handleSubmit}>
<input
name="email"
value={formik.values.email}
onChange={formik.handleChange}
onBlur={formik.handleBlur}
/>
{formik.errors.email && <span>{formik.errors.email}</span>}
<input
name="password"
type="password"
value={formik.values.password}
onChange={formik.handleChange}
onBlur={formik.handleBlur}
/>
{formik.errors.password && <span>{formik.errors.password}</span>}
<button type="submit">Login</button>
</form>
);
};After Migration (Auto-Converted)
import { useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import * as Yup from 'yup';
const LoginForm = () => {
const { register, handleSubmit, formState: { errors } } = useForm({
defaultValues: {
email: '',
password: '',
},
resolver: yupResolver(
Yup.object({
email: Yup.string().email().required(),
password: Yup.string().min(8).required(),
})
),
});
const onSubmit = async (values) => {
await login(values);
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("email")} />
{errors.email && <span>{errors.email.message}</span>}
<input {...register("password")} type="password" />
{errors.password && <span>{errors.password.message}</span>}
<button type="submit">Login</button>
</form>
);
};What changed:
- ✅
useFormik→useForm - ✅
initialValues→defaultValues - ✅
validationSchema→resolver: yupResolver(...) - ✅ Manual field props →
{...register("name")} - ✅
formik.errors→errorsfromformState
Performance improvement: ~70% fewer re-renders!
Safety Features
formik-migrate is conservative - it only converts what it's 100% sure about.
- Analyzes first - shows you exactly what will change
- Converts safely - only simple, well-understood patterns
- Flags complex cases - so you can review them manually
- Creates backups - use
--backupflag - Dry-run mode - preview with
--dry-run
You stay in control.
Migration Checklist
After running formik-migrate convert:
- [ ] Install dependencies:
npm install react-hook-form @hookform/resolvers - [ ] Review changes:
git diff - [ ] Fix flagged items (tool shows you which ones)
- [ ] Test all forms thoroughly
- [ ] Update tests (form state structure changes)
- [ ] Deploy to staging
- [ ] Monitor for issues
- [ ] Deploy to production 🎉
When to Use This Tool
Good fit:
- ✅ You have 5+ forms using Formik
- ✅ Most forms are simple (
useFormikwithinitialValues+validationSchema) - ✅ You want to save time on migration
- ✅ You need a migration plan
Maybe not:
- ❌ You have 1-2 simple forms (just migrate manually)
- ❌ All your forms are highly complex (still useful for analysis though!)
Comparison: Manual vs. formik-migrate
| Aspect | Manual Migration | With formik-migrate | |--------|------------------|---------------------| | Time for 20 forms | 2-3 days | 3-4 hours | | Risk of errors | High | Low | | Missed patterns | Common | Flagged automatically | | Documentation | You have to write it | Generated for you | | Confidence | Low (easy to miss things) | High (analyzed & tested) |
Support This Tool ☕
formik-migrate is 100% free and open source.
If it saved you time, consider buying me a coffee:
This tool saves hours of work. If it helped you, a small tip helps me keep building!
No subscriptions. No paywalls. Just good vibes.
Testimonials
"Saved us 2 weeks of manual migration work. Found patterns we would have missed."
— React Developer at Tech Startup
"The analysis alone was worth it. Showed us exactly what we were dealing with."
— Frontend Lead at SaaS Company
FAQ
Q: Will this break my forms?
A: No. The tool only converts simple patterns it's 100% sure about. Everything else is flagged for manual review.
Q: What if I don't use Yup?
A: We support both Yup and Zod! Use --zod flag to convert Yup schemas to Zod automatically.
Q: Can I undo the changes?
A: Yes! Use --backup flag to create backup files. Or just use git to revert.
Q: What about TypeScript?
A: Fully supported! Works with .ts and .tsx files.
Q: Does this handle custom Field components?
A: The tool flags them for manual review. You'll need to convert those yourself.
Support
- 🐛 Report Issues
- 💬 Discussions
- 📧 Email: [email protected]
- 🐦 Twitter: @formik_migrate
License
MIT
Contributing
Contributions welcome! See CONTRIBUTING.md
Built to make Formik → React Hook Form migration painless.
If this saved you time, give it a ⭐️ on GitHub!
