Closed
Description
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).
- There aren't any performance issues that I'm overlooking, are there?
- Can I add this to react-redux?
Metadata
Metadata
Assignees
Labels
No labels