What is the difference between a Presentational component and a Container component?
What is the difference between a Presentational component and a Container component?
In React, components can be categorized into two distinct types: Presentational components and Container components. Each type serves a specific purpose in the architecture of a React application, facilitating better organization, maintainability, and scalability of the code.
Presentational components, also known as "dumb" components, are primarily concerned with how things look on the user interface. They are not aware of where the data comes from. Their main responsibility is to present something to the DOM. Once they receive data and callbacks via props, they render the UI accordingly. These components are usually written as functional components unless they need to use lifecycle methods or local state for animations or similar concerns.
Key characteristics of Presentational components include:
Container components, on the other hand, are more concerned with how things work. They serve as the "brains" behind the presentational components, managing state and handling business logic. Container components provide data and behavior to presentational or other container components. They are typically class components because they need to handle state and lifecycle methods, although with the advent of hooks, functional components can also be used as containers.
Key characteristics of Container components include:
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào