React promotes the idea of thinking in components. It is about being able to break down the UI into a Component hierarchy. Each component will be created in a separate file.
Each component needs to be exported and then imported following the syntax of the ES6 module.
Just as you can compose functions or classes to create more complex solutions/models, you can compose simpler components to create more complex ones.
For example, you can create a Title
component, a Content
component, and a Comment
component. Then, you can compose them into an Article
component.
Moreover, you can compose the Article
component with other components to create a more complex component.
This way, you can create a complex UI by composing simpler components. This approach makes the code more readable, maintainable, and testable.
It is a common practice to store components in a components
directory. This directory will contain all the components used in the application. Each component will be stored in a separate file.