Course contentsShow
← React
Lesson 1544 of 2,39638. Server Components FundamentalsFree lesson

Third-Party Libraries and the Client Boundary

How importing packages that use hooks automatically pulls code into the client bundle.

Third-Party Libraries and the Client Boundary

You'll learn: Why importing third-party packages that use hooks automatically forces your components into the client bundle.

The Hidden Client Requirement

When you import a third-party library into a Server Component, React needs to determine whether that code can run on the server. Here's the catch: if the library uses any hooks like useState, useEffect, or useContext, it must run in the browser — and your component must become a Client Component too.

This happens automatically and invisibly. You don't see a 'use client' directive in the library's code (usually), but React detects the hook usage and treats the entire module as client-side code.

The Practical Impact

Imagine you import a popular animation library:

import { motion } from 'framer-motion';

export default function AnimatedCard() {
  return <motion.div>Hello</motion.div>;
}

Framer Motion uses hooks internally for animation state. The moment you import it, your component becomes a Client Component — even if you never wrote 'use client' yourself. The entire framer-motion package now ships to the browser.

The Analogy

Think of Server Components as a "server-only club." Third-party libraries are guests trying to enter. If a guest (library) brings equipment (hooks) that only works in the browser, security won't let them in the server door. Your component must meet them on the client side instead.

The Strategy

Check if libraries have server-compatible versions, or isolate their usage in dedicated Client Components marked with 'use client' at the lowest possible boundary. This keeps the rest of your component tree on the server.

Key Takeaway: Importing any package that uses hooks automatically makes your component client-side code, even without an explicit 'use client' directive — the module boundary crosses into client territory.