From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications

Unlock this course with a free trial

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

React state

React state

In this lesson, you'll learn how to use the UseState hook to manage state in your React components. We'll cover adding state variables, understanding the return values of UseState, adding multiple state variables, and finally, why state is considered local. Let's start with our SimpleApp component, returning a simple H1 element. Let's create a Counter.jsx file inside the src folder. Moving to Counter.jsx. This will house our Counter component, which we'll build step by step. At the moment, it returns an empty div. Going back to App.jsx. Now you will see that I have imported the Counter component into App.jsx and rendered it within the App component. This allows us to use the counter we are about to create within our main application. Moving to counter.jsx. Now it is time to add a simple counter variable to counter.jsx. I've declared a variable count and initialized it to 0. This is a normal JavaScript variable for now. Here I am adding some HTML to display our counter value. Let's add…

Contents