State
React functional state updater
Use a pure function of pending state for dependent updates.
Formal Syntax & Structure
react syntaxreact
setState(previous => previous + 1)Working Example
Example Snippetreact
import { useState } from "react"; function Pack() { const [n,setN]=useState(0); return <button type="button" onClick={()=>setN(p=>p+2)}>{n}</button>; }