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>

);

}

More from React.js Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details