Prerequisites
- Node.js 14 or higher
- Next.js 13+ (for App Router) or Next.js 12+ (for Pages Router)
- Basic familiarity with Next.js
Installation
First, install the required packages:Setup for App Router (Next.js 13+)
The App Router is the recommended approach for new Next.js applications.Step 1: Use in Client Components
Motion Icons React requires client-side JavaScript, so use the'use client' directive and import the CSS:
app/page.tsx
Important: Import the CSS file (
import 'motion-icons-react/style.css';) in any component that uses Motion Icons. Next.js will automatically handle the CSS bundling.Step 2: Create Reusable Components
For better organization, create reusable icon components:components/AnimatedIcons.tsx
app/page.tsx
Setup for Pages Router (Next.js 12+)
If you’re using the Pages Router, follow these steps:Step 1: Use in Pages
Import the CSS and use Motion Icons in your pages:pages/index.tsx
Common Use Cases
Loading States
Interactive Navigation
Form Validation Feedback
Troubleshooting
Animations not working
Animations not working
Problem: Icons appear but don’t animate.Solution:
- Make sure you imported the CSS in your layout/app file:
- Verify you’re using
'use client'directive in components that use animations - Clear Next.js cache:
rm -rf .next && npm run dev
Hydration errors
Hydration errors
Problem: Getting hydration mismatch errors.Solution:
- Ensure you’re using
'use client'in components with MotionIcon - Don’t use animations that depend on client-side state during SSR
- Use dynamic imports if needed:
Icons not showing in production
Icons not showing in production
Problem: Icons work in development but not in production build.Solution:
- Verify CSS is imported in the root layout
- Check that lucide-react is installed as a dependency (not devDependency)
- Clear build cache:
rm -rf .next && npm run build
TypeScript errors
TypeScript errors
Problem: TypeScript compilation errors.Solution:
- Ensure you have @types/react installed
- Update TypeScript to version 4.0 or higher
- Check that both packages are properly installed:
Performance Tips
1. Use Dynamic Imports for Heavy Pages
If you have many animated icons, consider lazy loading:2. Optimize Animation Triggers
Usetrigger="hover" or trigger="click" instead of trigger="always" to reduce continuous animations:
3. Limit Simultaneous Animations
Avoid having too many icons animating at once. Use animations strategically for important UI elements.Next Steps
Animation Types
Explore all available animations
Examples
See more real-world examples
API Reference
Complete props documentation
Accessibility
Learn about accessibility features