React Js UseState() Hook Example

Hello react js devs in this tutorial I am going to show how we can use useState() in our functional react component. if we use useState then no need to define your component as class based component. useState() is a Hook in react that allows you to have state variables in functional components. 

It is react hook. So using useState hook we can change our state value easily. If you don't know how react useState hook works then this example is for you to clear your concept.

Basically usestate took three parameters. Initial state, current state and a method. See the below example

const [count, setValue] = useState(0)


Look here 0 is initial state and we used array destructuring to define current state and method. here count is current state and setValue is method. Now in this example we will create a button and when we will click on this button then the value will be incremented. Let's see the example.


Now you can check it to run it browser. Hope it can help you and you've understand react useState hook.


#react-hooks #react-js