Course contentsShow
← React
Lesson 337 of 2,39610. useState BasicsFree lesson

Reading State in JSX

How to access and display state values directly in your component's JSX.

Reading State in JSX

What you'll learn: How to display your component's state values directly in your JSX output.

The Core Idea

Once you've created state with useState, you need to actually show it to your users. The state variable you destructured from useState is just a regular JavaScript variable — you can drop it into your JSX anywhere you'd use any other value.

Remember, JSX uses curly braces {} to embed JavaScript expressions. Your state variable is a JavaScript value, so it goes inside those curly braces.

How It Works

function Counter() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>The count is: {count}</p>
    </div>
  );
}

The {count} reads the current state value and displays it. When setCount is called and triggers a re-render, React re-runs your component function, gets the new count value, and updates what's on screen.

You Can Use State Anywhere in JSX

State isn't limited to text content:

function Greeting() {
  const [name, setName] = useState("World");

  return (
    <div>
      <h1>Hello, {name}!</h1>
      <p>{name} has {name.length} letters.</p>
      <input value={name} />
    </div>
  );
}

You can interpolate it, call methods on it, use it in attributes — it's just JavaScript.

Key Takeaway: State variables are plain JavaScript values you can embed in JSX with {} — they display the current state and automatically update on screen when state changes.