import React, { useState } from "react";
function Counter() {
// Defining state variable 'count' and its updater 'setCount'
const [count, setCount] = useState(0);
return (
<div>
<p>Count: {count}</p>
{/* Updating state on button click */}
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}
export default Counter;
The useState
hook provides a simple and effective way to introduce and manage state in functional components, enabling dynamic and interactive UIs.
Read this note on React Hooks - https://notes.thanni.co/react-hooks/