Manage State In A Functional Component
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 add local, component state to it.
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 React PowerPlug and Recompose.
However, projects using React 16.8+ have Hooks at their disposal. The Hooks API's base offering is a state hook -- useState
.
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.
Last updated