Chapter 2: Crafting States in Functions

In the previous chapter, we learned how to write function components in React. In this chapter, we will craft a special variable called a state in the function components. We will see what benefits a state can bring us, including requesting a new update, making a variable persistent, listening to a value change, as well as performing tasks upon the mount. We will also see an example of applying a state to a single-page application. In the end, we will look closely at what role the states play within the UI.

We will cover the following topics in this chapter:

  • Crafting a state in a function component
  • Applying states to single-page applications
  • How states work with UIs
  • Questions and answers

Technical requirements ...

Get Designing React Hooks the Right Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.