Hooks
React useState
Retain local state for a mounted component and request updates.
Formal Syntax & Structure
react syntaxreact
const [state, setState] = useState(initialState)Working Example
Example Snippetreact
import { useState } from "react"; function Pack() { const [n,setN]=useState(0); return <button type="button" onClick={()=>setN(n+1)}>{n}</button>; }