From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Introduction to the useState

Introduction to the useState

Hi and welcome to lesson number 5. In this lesson, we will discuss about states, event handling and functional components. State is a way to store data that can change over time in a component. Whenever a state is changed, it causes React to re-render the component and update it on the screen. State variables are local to a component. If we want to pass on the state variable to any other component, we can use props for it. That's a simple declaration of how we can create a state variable using the UState hook. Let's discuss the UState hook in more detail. UState is a hook that manages the state in function components. It provides us with a field and a setter function. The variable can infer the data type based on the defined value. For example, over here the name is automatically going to be of type string because the value passed to it is a string named guest. If we change the value of string to boolean, then the name would automatically be of boolean type. It has a very simple…

Contents