Skip to content

Rule proposal: no impure mapStateToProps #20

Closed
@lencioni

Description

@lencioni

Since connected components are PureComponents, it is important for mapStateToProps to avoid creating new objects with identical data every time. If this happens, it will cause unnecessary re-renders, leading to bad performance.

Writing a rule to catch all of these scenarios might be too difficult, but there is probably a subset of scenarios that could be trivially linted against. Consider the following mapStateToProps:

function mapStateToProps(state) {
  return {
    foo: {
      bar: state.foobar,
    },
  };
}

What do you think about adding a rule that flags a few of these simple cases?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions