Document_useState
Document_useState
1. What is it?
useState is a React Hook that lets you add a state variable to your component.
state is a state variable and setState is a function that updates the state value.
In order to make use state variables in our React Component we can make use of useState hook.
For example:
return (
<>
<input
value={name}
/>
Increment age
</button>
</>
);
Creating state variables to store some data and also passing that data to other components.
If we want to store some data within our component , we can make use of useState to declare a state
variable to store that data into it.That data could be passed to other component via props as well.
function FavoriteColor() {
return (
<>
<button
type="button"
>Blue</button>
</>
Output:
Initial Render:
On Button Click: