Container Component (Stateful Component)
A container does data fetching and then renders its corresponding sub-component.
Assume that you have a component that displays comments, you didn't know about container components, so you put everything in one place.
Your component is responsible for both fetching data and presenting it. There's nothing wrong with this but you miss out on a few benefits of React.
CommentList
can't be reused unless under the exact same circumstances.
Lets pull out data-fetching into a container component.
Now, let's rework CommentList
to take comments as a prop.
What we got:
- Separated our data-fetching and rendering concerns
- Made our
CommentList
component reusable - Given
CommentList
the ability to set PropTypes