Using Props in Components
How do you use props in your components? And when do you need them?
The second question will be answered in greater detail a little bit later. For the moment, it’s enough to know that you typically will have some components that are reusable and, therefore, need props and some components that are unique and might not need props.
The “how” part of the question is the more important part at this point, and this part can be split into two complementary problems:
- Passing props to components
- Consuming props in a component
Passing Props to Components
How would you want props and component configurability to work if you were to design React from the ground up?
Of course, there would be a broad variety of possible solutions, but there is one great role model that can be considered: HTML. As mentioned above, when working with HTML, you pass content and configuration either between element tags or via attributes...