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

What is the difference between Component and Container in Redux?

Câu trả lời

In React and Redux, the terms "Component" and "Container" refer to different roles within the application's architecture, primarily focusing on how they interact with the Redux store and manage data.

Components

Components in React are the building blocks of the application's user interface. They are reusable, encapsulated elements that manage their own state and compose the visual representation of the application. Components are primarily concerned with how things look and can be either class or functional components. They receive data through props and may maintain local state. Components are often referred to as "presentational components" because their only responsibility is to present something to the DOM. When used in the context of Redux, these components are usually not aware of the Redux store and receive all data via props[1][2].

Containers

Containers, sometimes called "smart components" or "connected components," are React components that connect directly to the Redux store. They do not concern themselves with direct rendering but rather with handling the logic of state management. Containers subscribe to Redux state updates and dispatch actions to the store. Their main role is to pass data and actions down to presentational components by using props. This approach keeps the presentational components decoupled from the state management logic, which can promote better maintainability and scalability of the application[1][2][3].

Containers typically make use of the connect function from react-redux to read from the state and disp...

junior

junior

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

middle

What is {this.props.children} and when you should use it?

junior

What's the difference between a Controlled component and an Uncontrolled one in React?

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