Skip to main content
This guide will walk you through setting up Motion Icons React in your Next.js application, whether you’re using the App Router or Pages Router.

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
Then use them in any component:
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

Problem: Icons appear but don’t animate.Solution:
  1. Make sure you imported the CSS in your layout/app file:
  2. Verify you’re using 'use client' directive in components that use animations
  3. Clear Next.js cache: rm -rf .next && npm run dev
Problem: Getting hydration mismatch errors.Solution:
  1. Ensure you’re using 'use client' in components with MotionIcon
  2. Don’t use animations that depend on client-side state during SSR
  3. Use dynamic imports if needed:
Problem: Icons work in development but not in production build.Solution:
  1. Verify CSS is imported in the root layout
  2. Check that lucide-react is installed as a dependency (not devDependency)
  3. Clear build cache: rm -rf .next && npm run build
Problem: TypeScript compilation errors.Solution:
  1. Ensure you have @types/react installed
  2. Update TypeScript to version 4.0 or higher
  3. 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

Use trigger="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