The useState hook is a built-in hook that allows functional components to manage state. It's commonly used when you need to add state to a component without converting it into a class.
Here's a basic overview of how to use useState:
import React, { useState } from 'react';
function ExampleComponent() {
// Here, we declare a state variable called "count" and a function to update it, "setCount".
// We initialize the state with a value of 0.
const [count, setCount] = useState(0);
return (
You clicked {count} times
{/* When the button is clicked, we call setCount to update the state */}<button onClick={() => setCount(count + 1)}> Click me
export default ExampleComponent;
1: Clone the Project
2: Simply run the command npm install - First to install all the packages
3: Run the project using npm start