State

React state batching

Ordinary synchronous event updates are grouped before the resulting UI update; exact render counts are not a contract.

Formal Syntax & Structure

react syntaxreact
setCount(n => n + 1); setCount(n => n + 1);

Working Example

Example Snippetreact
import { useState } from "react"; function Pack() { const [n,setN]=useState(0); return <button type="button" onClick={()=>{setN(p=>p+1);setN(p=>p+1);}}>{n}</button>; }
React Reference