From the course: React Practice for Beginners: Build and Modify Basic Components
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Managing a component state with useState - React.js Tutorial
From the course: React Practice for Beginners: Build and Modify Basic Components
Managing a component state with useState
- [Instructor] Our next topic are hooks. The functional components are quite easy to write, but originally, they had a big limitation. They couldn't have their own state. And that changed with hooks, and that actually made functional components the default go-to for writing components. So hooks must be pretty great, you might think. Let's talk about them. Hooks are special built-in functions that let functional components manage state and use other React features. The most commonly used hook is probably UseState. This hook let's the component store values that can change over time, like a counter value or form input. When the data of the state is changed, the component is automatically re-rendered, and the change is reflected in the user interface. There are some other common hooks as well. For example, UseEffect for running side effects like fetching data, UseRef for keeping a reference to a value between renders without causing re-render, and UseContext for sharing data between…