Migrating from Version 2 to Version 3
Version 3 of React Icons introduced significant improvements including better tree-shaking support and a new import pattern. This guide will help you migrate your codebase smoothly.Breaking Changes
1. Import Syntax Change
The most significant change in v3 is the new import syntax.- v2 (Old)
- v3 (New)
- v2 used default imports from individual icon files
- v3 uses named imports from icon pack modules
- v3 enables better tree-shaking and smaller bundle sizes
2. Vertical Alignment Removed
Version 3 removed the automaticvertical-align: middle CSS property. You now need to add this manually if needed.
3. TypeScript Support
Version 3 includes native TypeScript support. You can remove the separate type definitions package:Migration Steps
Update import statements
Replace all old-style imports with the new syntax. You can use find-and-replace:Find pattern:
import (\w+) from "react-icons/lib/(\w+)/.*"Replace with: import { $1 } from "react-icons/$2"Depending on your icon usage, you may need to adjust imports manually if you’re using multiple icons from the same pack.
Add vertical alignment (if needed)
If your design relies on vertical alignment, add it back using one of the methods described above.
Remove TypeScript type definitions
If you’re using TypeScript, remove the
@types/react-icons package as v3 includes native type definitions.Common Issues
Bundle size increased after migration
Bundle size increased after migration
This usually happens when you’re not using ES6 imports correctly. Make sure you’re using named imports:See the Tree-Shaking guide for more details.
Icons appear misaligned
Icons appear misaligned
Version 3 removed automatic vertical alignment. Add it back using IconContext or inline styles as described above.
TypeScript errors after migration
TypeScript errors after migration
Remove the
@types/react-icons package - v3 includes native TypeScript support and the type definitions may conflict.Icons not rendering
Icons not rendering
Make sure you’ve updated your import statements to use the new syntax. The old import paths will not work in v3.
Benefits of v3
Upgrading to version 3 provides several benefits:Better Tree-Shaking
Dramatically reduced bundle sizes with proper ES6 module support
Native TypeScript
Built-in type definitions with no external package needed
Simpler Imports
Cleaner import syntax that’s easier to read and write
Better Performance
Optimized rendering and smaller runtime footprint
Need Help?
If you encounter issues during migration:FAQ
Check common questions and answers
Troubleshooting
Find solutions to common problems