Course contentsShow
← React
Lesson 526 of 2,39615. useEffect FundamentalsFree lesson

Common Side Effects in React

Identify typical side effects: API calls, DOM manipulation, timers, subscriptions, and logging.

Common Side Effects in React

What you'll learn: The typical side effects you'll encounter when building React applications.

Now that you understand what side effects are (operations that reach outside pure function logic), let's identify the most common ones you'll handle in React apps.

The Big Five Side Effects

1. API Calls / Data Fetching The most frequent side effect. Fetching data from a server isn't pure—it depends on network conditions, server state, and external data that React doesn't control.

2. DOM Manipulation Directly interacting with the DOM outside React's control: scrolling to elements, measuring sizes, focusing inputs, or integrating third-party libraries that need direct DOM access.

3. Timers Using setTimeout or setInterval creates side effects because they schedule future operations and maintain state outside your component's scope.

4. Subscriptions Setting up event listeners (window resize, WebSocket connections, browser events) or subscribing to external data sources. These establish ongoing relationships with outside systems.

5. Logging and Analytics Sending tracking events, console logging for debugging, or reporting errors to monitoring services. These operations communicate with the outside world without affecting render output.

Why These Matter

Think of your component as a sealed room. These five operations are like opening windows to interact with the outside world—the network, the browser, time itself, or external services. Each needs special handling because they:

  • Happen after rendering
  • Can't occur during the pure render phase
  • Often need cleanup when the component unmounts
  • May depend on specific prop or state values

Recognizing these patterns helps you understand when you need to reach for side effect tools (like refs or, soon, other mechanisms) instead of trying to handle them during rendering.

Key Takeaway: The most common React side effects are API calls, DOM manipulation, timers, subscriptions, and logging—all operations that interact with systems outside your component's pure render logic.