What is useState ?

Himanshu Rawat
Aug 31, 2022

useState is a Hook that lets you add React state to function components. we can use useState to update the data after a particular event.

useState hook needs to be imported from react as below

https://medium.com/media/0dc04a1647c03cdd2c9bb2433447acd1/href

How it is used?

It is generally used in a destructured manner where we have a current state here as count and second is a function setCount used when we need to manage change in value.

count -> current value

setCount -> value after change of count

useState(0) means count having initial value zero

Note you can set any initial value

--

--