S
Seoffix.com
Sign In Get Pro Membership

React & Modern Frontend

State with useState

Intermediate React 35 XP

State with useState

useState returns the current value and a setter. Calling the setter re-renders the component.

Example

const [on, setOn] = useState(false);

Your task

Create a count state starting at 0 and a button that adds one.

Hints

  1. useState(0) gives count and setCount
  2. onClick calls setCount(count + 1)

Check your understanding

Answer every question to pass.
1. What does calling a state setter do?

Your answer

This lesson is checked against the lesson rules. Your code is never run on our servers.

AI Code Explainer & Translator

Runs without any outside service.
 
Mark Complete & Earn XP
Earn 35 XP after you pass the quiz. Finish every lesson in the track to earn its certificate.
Sign in to earn XP

React & Modern Frontend

Lessons in this track
Questions about this lesson? Ask the Coding & Web Dev squad. Discuss in Community