Enforces that mapStateToProps does not bind complete store to a component. (react-redux/mapStateToProps-no-store)
Passing whole state to a component is a bad practice, triggering unnecessary re-renders. Additionally bad is passing around a mutable object that your component critically depends on preventing mutations to. Instead one should specify the properties actually used by a component.
The following patterns are considered incorrect:
const mapStateToProps = (state) => state
const mapStateToProps = state => {
return {state: state}
}
const mapStateToProps = state => ({...state});
connect((state) => state, null)(App)
The following patterns are correct:
const mapStateToProps = () => {}
const mapStateToProps = (state) => {isActive: state.isActive}
const mapStateToProps = ({isActive}) => {isActive}
connect((state) => ({isActive: state.isActive}), null)(App)
Please note that the following use case, although common, is not supported due to the nature of static code analysis.
The following would not warn:
const getProps = (state) => state;
const mapStateToProps = (state) => getProps(state);