Skip to content

State

In one line

State is internal data a component owns and can change over time. When state changes, React re-renders the component.

In simple words

State is a component's memory. It holds data that can change — a counter value, a toggle flag, text a user typed, fetched data — and when that data changes, React automatically re-renders the component to reflect the new state.

You declare state with the useState hook: const [count, setCount] = useState(0). The first element is the current value; the second is a setter function. You never modify state directly — always call the setter, which schedules a re-render.

State is local and private to the component. If two instances of the same component exist, each has its own independent state. To share state across components, lift it up to a common parent or use Context.

Example

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

count is state. Clicking the button calls setCount with a new value, which triggers a re-render showing the updated count.

Common confusions

  • Confused with: props

    The difference: State is internal and mutable by the component itself. Props are external and read-only, passed from the parent. Use state for data the component owns; use props for data the parent controls.

Related terms

Related Resources

Related Lessons

  • State

    Learn how to use useState and manage component state.

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary