DrSchool Learn coding, fast.
EN AR BN CS DE EL Search

REACT: State

Learn State in REACT with practical examples.

Read time: 1 min Words: 33
My Progress

REACT — State

Overview

State stores UI data that can change over time.

What you'll learn

  • useState
  • updating state
  • re-render

Syntax

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

Example

import { useState } from "react";

export default function Counter(){
  const [count, setCount] = useState(0);
  return (
    <button onClick={()=>setCount(count+1)}>
      Clicks: {count}
    </button>
  );
}

Notes

  • Never mutate state directly.
  • State update triggers re-render.