React & Modern Frontend (445 Qs)•Part 5: React Redux State Management (101 - 134)
What is the difference between component and container in React Redux?
Component is a class or function component that describes the presentational part of your application.
Container is an informal term for a component that is connected to a Redux store. Containers subscribe to Redux state updates and dispatch actions, and they usually don't render DOM elements; they delegate rendering to presentational child components.
Practical Code Example
jsx
// Component (Presentational): Receives props, renders JSX
function UserList({ users }) {
return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>;
}
// Container: Connected to Redux store, passes state and dispatch to Component
function UserListContainer() {
const users = useSelector(state => state.users.list);
return <UserList users={users} />;
}