Skip to content

Instantly share code, notes, and snippets.

@axelnormand
Last active January 5, 2018 16:30
Show Gist options
  • Save axelnormand/ec5c68b6366e07bd9193b75781ba43d1 to your computer and use it in GitHub Desktop.
Save axelnormand/ec5c68b6366e07bd9193b75781ba43d1 to your computer and use it in GitHub Desktop.
Select util function for redux - saves milliseconds in your typing :)
// @flow
export const select = (selectors: Object) => (state: Object): Object => {
const keys = Object.keys(selectors);
const ret = {};
keys.forEach(key => {
if (!selectors[key]){
throw new Error(
`
Could not find key '${key}' in selectors.
Perhaps you the selector doesn't exist or is misspelt?
Or maybe imported selector in component is misspelt?
`,
);
}
ret[key] = selectors[key](state);
});
return ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment