Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helper function for simplifying mapStateToProps #749

Closed
baron816 opened this issue Jul 16, 2017 · 1 comment
Closed

Helper function for simplifying mapStateToProps #749

baron816 opened this issue Jul 16, 2017 · 1 comment

Comments

@baron816
Copy link

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?
@timdorr
Copy link
Member

timdorr commented Jul 16, 2017

There's already an open PR for this: #724

@timdorr timdorr closed this as completed Jul 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants