3 ms·
The "container component" pattern is widely used throughout the React world - it's simply any component whose primary responsibility is retrieving some data, an
by acemarke 10y ago
The "container component" pattern is widely used throughout the React world - it's simply any component whose primary responsibility is retrieving some data, and passing that as props to children. Could be making an AJAX call in `componentDidMount`, or something else. In this case, the container components generated by `connect` simply manage a subscription to the Redux store, retrieve the current state when notified, and run your `mapState` and pass the result down. Absolutely no magic at all, and definitely not "also changing any component's state without you knowing it".
Dan Abramov wrote a simplified version of `connect` to illustrate what it does: https://gist.github.com/gaearon/1d19088790e70ac32ea636c025ba424e https://gist.github.com/gaearon/1d19088790e70ac32ea636c025ba... .
As for other libraries, they're still dispatching actions, which means that all updates to the store are traceable (especially if you're using the Redux DevTools).