React Hook: useState
Learn about the React hook useState.
We'll cover the following
React hooks
Prior to React 16.8, the only way to access state
in a React component was by composing with JavaScript’s class
component. Functional components weren’t optimal since they were only used as presentational components. React 16.8 changed all that and introduced the concept of hooks, in which a functional component can hook into the React state and the lifecycle methods.
Note: Hooks only work in functional components. They don’t work in
class-based
components.
The useState
hook
The useState
hook adds a local state
to a React component. See the code below:
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy