From the course: React: State Management
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
useState: From stateless to stateful components - React.js Tutorial
From the course: React: State Management
useState: From stateless to stateful components
- The Hooks were first introduced in 2018. They have been a new additions to the React library since the version 16.8. The Hooks give developers the ability to create stateful components, and use other React features without having to write a class. In other words, Hooks are functions that lets you hook into the React states and lifecycle features from a function components. And so the React API provides with a few built-in hooks like useState. useState is a React Hook that lets you add and store local state variables in a components. And this is how the syntax looks like. Whenever you call useState in a component, it returns an array, with first, a variable and a function, to update the state. A new state can take a value as a parameter of any type to set an initial value. In this module, we cover how to manage the state effectively in a React project by using the React built-in Hooks. The next example is a math game…