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

Interactive Features Require 'use client'

useState, useEffect, event handlers, and browser APIs all force a component to be client-side.

Interactive Features Require 'use client'

What You'll Learn

You'll understand exactly which React features force a component to become a client component, requiring the 'use client' directive.

The Interactivity Line

Server Components are fantastic for static content and data fetching, but the moment you need user interaction, you've crossed into client territory. Think of it like a restaurant menu versus an ordering kiosk—one is static information, the other needs to respond to touches and clicks.

Features That Require Client Components

Any of these features immediately mean your component must be marked with 'use client':

State Hooks

  • useState - Managing changing values requires client-side JavaScript
  • useDeferredValue, useOptimistic - All state management lives on the client

Effect Hooks

  • useEffect - Side effects happen in the browser, not during server rendering

Event Handlers

  • onClick, onChange, onSubmit - User interactions need JavaScript to execute
  • Any function that responds to user actions

Browser APIs

  • window, document, localStorage
  • Anything that only exists in a browser environment

The Pattern

'use client'  // Required!

import { useState } from 'react'

export function Counter() {
  const [count, setCount] = useState(0)
  
  return (
    <button onClick={() => setCount(count + 1)}>
      Clicked {count} times
    </button>
  )
}

Without 'use client', this component would fail—Server Components don't have access to state or event handlers.

Key Takeaway: If your component uses useState, useEffect, event handlers, or browser APIs, it must be a client component with 'use client' at the top. Interactivity = client-side JavaScript.