Skip to content
BENIBIX Learn

UI State

Development🌐 Web DevelopmentFrameworks

Also known as State, Component State, Application State

The data a page holds right now that can change, like a count.

Think of it like

Think of it like a scoreboard. When the score changes, the board shows the new number.

Example

Jack's cart icon shows a number. That number is state, and adding a mug changes it from 2 to 3.

Why it matters

Most front-end bugs are state bugs. Knowing where state lives makes them easy to find.

Definition

State is the data a page holds right now that can change. A count, a typed word or an open menu are all state. When the state changes, the framework draws the affected parts of the page again. You do not change the screen by hand; you change the state, and the screen follows. State can live in one component or be shared across the whole app. Keeping it small and in one place makes bugs rarer.

Example code

jsx
const [count, setCount] = useState(0);
<button onClick={() => setCount(count + 1)}>{count}</button>
Each click changes the state, and the button shows the new count.

Common mistake

Keeping the same fact in two pieces of state. They drift apart, and the screen shows two answers.

Key takeaways

  1. 1
    Data that changes. Counts, inputs, open or closed.
  2. 2
    The screen follows. Change state, not the page.
  3. 3
    One home per fact. No copies to drift apart.

Compare