In the previous post we saw that the useState Hook is used to define state props in a function component, in this post we shall see a small example on how the useState hook works in action.
In this post we will create a function component and define a state prop count using the useState hook, we will attach a function setCount which will be used to change the value of the count prop. We will also attach the setCountfunction to the click event handler of a button, so that each time the button is clicked the setCount function will be called which will increase the value of the count state prop by 1.
In this post we will create a function component and define a state prop count using the useState hook, we will attach a function setCount which will be used to change the value of the count prop. We will also attach the setCountfunction to the click event handler of a button, so that each time the button is clicked the setCount function will be called which will increase the value of the count state prop by 1.