M. Kodirov

STAGE 02 / LESSON 03

React state and effects

State remembers information that can change between renders.

THE IDEA

Understand it.

Use state for values the UI needs to remember, such as whether a task is complete. Calling a state setter schedules a render with a new value. When the next value depends on the previous one, use the updater form.

An effect synchronizes a component with something outside React, such as a browser subscription. Derive simple values during rendering instead of using an effect to duplicate state. Clean up subscriptions when the effect ends.

SEE IT IN CONTEXT

Toggle a task

"use client";
import { useState } from "react";

function DoneButton() {
  const [done, setDone] = useState(false);
  return (
    <button onClick={() => setDone(previous => !previous)}>
      {done ? "Done" : "Mark done"}
    </button>
  );
}

React re-renders when state changes. The updater receives the previous value, avoiding reliance on a stale snapshot.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

GitHub

Public code checked November 2026

Interaction state in a button

Primer Brand's public button component uses React state for interaction and includes pointer and focus handlers.

  1. Interaction
  2. Event handler
  3. React state
  4. Rendered button

What to learn: State connects an event to the next rendering of the component. The source is a specific open-source button.

Read the source: Primer Brand button source

Spotify

Spotify engineering, 2021

Hooks expose platform capabilities

Spotify described exposing platform APIs to its React interface through React Hooks in its shared client architecture.

  1. React UI
  2. React Hooks
  3. Platform APIs

What to learn: Hooks can connect components to capabilities outside their immediate markup; the report does not specify every effect or state value.

Read the source: Spotify desktop and web architecture

TRY IT YOURSELF

Practice.

The interface needs a count of completed tasks. Store another count state or calculate it from the task list?

Show one possible answer

Usually calculate it from the task list during rendering. That avoids keeping two values in sync.

GO DEEPER

Official references.