Câu hỏi phỏng vấn Reactjs
Câu hỏi

What is the difference between a Presentational component and a Container component?

Câu trả lời

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

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:

  • They focus on the UI rather than behavior.
  • They receive data and callbacks exclusively through props.
  • They often contain no state (except UI state) and are typically functional components.
  • They are generally easier to write and maintain because they have fewer dependencies on the rest of the application[1][2][3][4].

Container Components

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:

  • They manage data and state for other components.
  • They may contain both presentational and other container components.
  • They are c...
junior

junior

Gợi ý câu hỏi phỏng vấn

senior

Describe Flux vs MVC?

junior

What are two types of components in ReactJS?

senior

When shall we use useReducer hook in ReactJS?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào