Skip to main content
Extend your app’s functionality with NPM packages.

Installing Packages

Via AI

Simply ask:
"Install react-hook-form for better form handling"
"Add date-fns for date formatting"
The AI will:
  1. Add the package to package.json
  2. Import it where needed
  3. Use it in your code

Automatic Installation

When AI writes code using a package, it’s automatically installed on next preview refresh.

Forms

PackageUse Case
react-hook-formForm state management
zodSchema validation
@hookform/resolversZod + react-hook-form
"Add a contact form using react-hook-form with Zod validation"

Dates

PackageUse Case
date-fnsDate formatting/manipulation
dayjsLightweight date library
"Format the created_at date using date-fns"

UI Enhancements

PackageUse Case
framer-motionAnimations
react-hot-toastToast notifications
sonnerModern toast library
"Add entrance animations using framer-motion"

Data Fetching

PackageUse Case
@tanstack/react-queryData fetching & caching
swrData fetching hooks
"Use React Query to fetch and cache the user data"

Charts

PackageUse Case
rechartsReact charts
chart.jsCanvas charts
react-chartjs-2Chart.js for React
"Add a line chart showing monthly revenue using recharts"

Utilities

PackageUse Case
lodashUtility functions
clsxConditional classes
uuidGenerate unique IDs

Using Installed Packages

Once installed, use in your code:
// Importing
import { format } from 'date-fns';
import { motion } from 'framer-motion';
import { useForm } from 'react-hook-form';

// Using
const formattedDate = format(new Date(), 'MMM d, yyyy');

Pre-Installed Packages

These are already available:

Core

  • next - Framework
  • react - UI library
  • typescript - Type safety
  • tailwindcss - Styling

shadcn/ui Dependencies

  • @radix-ui/* - Headless components
  • lucide-react - Icons
  • clsx - Class utilities
  • tailwind-merge - Tailwind class merging

Database

  • @supabase/supabase-js - Database client

Package Versions

Checking Versions

Ask AI to check or update:
"What version of react-hook-form is installed?"
"Update framer-motion to the latest version"

Version Compatibility

The AI typically installs compatible versions. If you need a specific version:
"Install react-hook-form version 7.48.0"

TypeScript Types

Many packages include types. For those that don’t:
"Install the TypeScript types for lodash"
This adds @types/lodash.

Common Package Tasks

Add Authentication

"Add OAuth login with the next-auth package"

Add Email

"Install @sendgrid/mail for sending emails"

Add Markdown

"Add support for rendering markdown content using react-markdown"

Add PDF Generation

"Install @react-pdf/renderer for generating PDF invoices"

Package Size Considerations

Be mindful of bundle size:

Check Size

Use bundlephobia.com to check package sizes.

Lightweight Alternatives

HeavyLighter Alternative
moment.jsdate-fns, dayjs
lodashlodash-es, individual imports
axiosnative fetch

Tree Shaking

Import only what you need:
// ❌ Imports entire library
import _ from 'lodash';

// ✅ Imports only needed function
import debounce from 'lodash/debounce';

Server vs Client Packages

Server-Only

Some packages should only run on server:
// This runs only on server
import { someServerThing } from 'server-package';

export async function GET() {
  // Use server package here
}

Client-Only

Some packages need browser APIs:
'use client';

import { ClientComponent } from 'client-package';

Troubleshooting

  • Check package name spelling
  • Package might not exist on npm
  • Try searching npmjs.com for correct name
  • Refresh the preview
  • Package might need time to install
  • Check import path is correct
  • Install @types/package-name
  • Some packages include types already
  • Check package documentation
  • Ask AI to resolve version conflict
  • Check peer dependencies
  • May need to update other packages

Best Practices

Use established packages

Choose well-maintained packages with good documentation

Check bundle size

Consider impact on app performance

Import selectively

Import only functions you need

Keep updated

Update packages for security fixes

Custom Fonts

Add typography packages