If you're using React, the "recommended" way would be to use the <Provider> component that comes along with the react-redux library, and have all of your app components as children inside the Provider component.
ReactDOM.render(
<Provider store={createStore(todoApp)}>
<TodoApp />
</Provider>,
document.getElementById('root')
);
What this does is it makes the store available to all of the children components through context.
So you could do something like const state = this.context.store.getState() in one of your components. But instead of doing this, it is recommended to use connect() provided by react-redux
connect() and performanceSince state is anyway available to all of the children components, you can have your mapStateToProps function in your container components, and return only those parts of the state that could be passed on as props to the corresponding presenter components.
function mapStateToProps(state) {
const { todos, visibilityFilter } = state;
return {
todos,
visibilityFilter
}
}
function mapDispatchToProps(dispatch) {
...
export default connect(mapStateToProps, mapDispatchToProps)(TodoApp);
For a better performant Redux, if you remember only one thing, let it be this: mapStateToProps is the new render; called on every store update ... and in this context, the connect() function (which returns a higher order component that wraps around your presenter component) already optimises for updates based on any changes in the part of the state it passes down as props to the presenter component.
So it only makes sense to pass only the required parts of the state as props through mapStateToProps. So if there are no changes to these props, connect() will optimise for whether the component should update or not.
If you want a detailed outlook into React/Redux perf. concepts, this GitHub issue serves as a great FAQ. This presentation on the same topic, is also awesome.