In the previous chapter, we learned about Elements and how they can be composed to create a basic user interface. Now, we'll learn how to group Elements together to form Components. We'll cover:
In short, a component is a special function that takes input properties and outputs an Element. Much like a function encapsulates some specific computation task, a Component encapsulates some specific rendering task – typically, rendering an isolated part of the user interface.
Let's use a Reddit post as an example:
If we look at the layout of the component, we notice quite a few buttons and pieces of functionality:
If we included all this functionality in one rsx!
call it would be huge! Instead, let's break the post down into Components:
In this chapter, we'll learn how to define these components.