DEV Community

Cover image for UseState Hook React
Harshil shah
Harshil shah

Posted on

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)