Need Assistance?

support@tutorialshub.in

React Hooks

useEffect and Side Effects

React.js Free Lesson
5 min read
ADVERTISEMENT

What is a Side Effect?

A side effect is work that needs to synchronize the component with something outside the normal rendering calculation. Examples include timers, subscriptions, browser APIs, and network requests.

useEffect

The useEffect Hook lets a component perform this synchronization after rendering.

Dependency Array

  • []: The effect does not re-run because of changing component values.
  • [value]: The effect re-runs when value changes.
  • No array: The effect runs after every render.

Cleanup

If an effect creates a timer, subscription, or event listener, return a cleanup function to remove it when necessary.

Important Advice

Do not use useEffect for ordinary calculations that can be performed during rendering. Effects are primarily for synchronization with external systems.

ADVERTISEMENT