Manage State In A Functional Component
Last updated
Was this helpful?
Last updated
Was this helpful?
Before the introduction of React 16.8, you had a couple options for declaring and managing state in your components.
The first class way was to create a class component and then .
If you already had a functional component, you could avoid the conversion to a class component with custom HOCs and Render Prop components or any number of third-party libraries such as and .
However, projects using React 16.8+ have at their disposal. The Hooks API's base offering is a state hook -- .
You can manage a variety of state values in a functional component with useState
. The useState
function takes the initial state value as an argument and returns a tuple with the current state value and an setter function for updating that piece of state.