📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials React Modern Development useState

useState

5 min read Quiz at the end
useState stores values between renders: const [count, setCount] = useState(0). Call the setter to update state and trigger a re-render. Use the functional form setCount(prev => prev + 1) when new state depends on old.

useState Hook

import { useState } from "react";

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

  return (
    

Count: {count}

); }
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which hook manages local state?
💡 useState is the primary hook for local component state.
2. useState returns:
💡 useState returns an array: const [state, setState] = useState(initial).
3. What triggers a re-render?
💡 Calling the setter function returned by useState triggers a re-render.
4. What is the initial value in useState(0)?
💡 The argument to useState() is the initial state value — here 0.
5. Functional update — when should you use setState(prev => ...)?
💡 Use functional updates (setState(prev => newVal)) when the new value depends on the old one.