Skip to content

Helper function for simplifying mapStateToProps #749

Closed
@baron816

Description

@baron816

I've written this simple function that I believe simplifies creating mapStateToProps:

export function makeProps(selectors) {
  return function (state, ownProps) {
    return Object.keys(selectors).reduce(function(acc, key) {
      acc[key] = selectors[key](state, ownProps);
      return acc;
    }, {});
  };
}

This will allows me to do const mapStateToProps = makeProps({products, total}); where products and total are selector functions. I believe it's somewhat similar to combineReducers (at least in spirit).

  1. There aren't any performance issues that I'm overlooking, are there?
  2. Can I add this to react-redux?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions