Mid
From PDF
React
React.js
Explain the useState hook with an example.
useState lets you add state to functional components.
✅ Syntax:
const [state, setState] = useState(initialValue);
✅ Example:
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png