Hooks

React state setter

Request a replacement or calculate pending state through an updater; the setter returns no value.

Formal Syntax & Structure

react syntaxreact
setState(nextState)

Working Example

Example Snippetreact
import { useState } from "react"; function Toggle() { const [on,setOn]=useState(false); return <button type="button" aria-pressed={on} onClick={()=>setOn(!on)}>Ready</button>; }
React Reference