What are components?
React components are the reusable building blocks we use to create the user interface of our app.
Components are the
type of the React element.
We've already seen a few built-in components:
Button. We can also define custom components.
This is analagous to classes and instances.
Viewis like a class, while
React.createElement(View)instantiates the class.
There are 2 ways we can define a React component:
- Function components - A function that takes parameters (called
props) as input, and returns a React element
- Class components - A
React.Componentand implements a
Lets take a look at each way we can define a React component.
The function component API is the one we should use for new code, and the one we'll focus on. The class component API is older, but you'll definitely still see it in examples online.
Want to learn React Native in-depth?