DEV Community

Cover image for UseState Hook React
Harshil shah
Harshil shah

Posted on

4

UseState Hook React

UseState Hook

The React useState Hook allows us to track state in a function component.

State generally refers to data or properties that need to be tracking in an application.

import React,{useState} from 'react';

function Example(){
const [count,setCount] = useState(0);
return(
    <div>
        <p>you have clicked {count} times</p>
        <button onClick={()=> setCount(count+1)}>
        Click Me
        </button>
    </div>

    );
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay