useState

Learn how to add and manage states in function components.

Initializing the state

This Hook returns a value as well as a function to us, which we can use to update the value. We can initialize the state using this Hook in the following way:

const [state, setState] = useState(initialState);

During the first rendering of a component that uses this Hook, this value is equal to the initialState that you pass to the state. If the parameter that has been passed ...