Last active
September 13, 2017 22:54
-
-
Save andycarrell/86a26c0ca18dd52c2aa122d318976c2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux'; | |
import * as selectors from '../selectors'; | |
const fnNameFor = ([first, ...rest]) => (`get${first.toUpperCase()}${rest.join('')}`); | |
const selectFor = key => selectors[fnNameFor(key)]; | |
const getMapStateFor = stateKeys => state => stateKeys.reduce( | |
(acc, key) => ({ ...acc, [key]: selectFor(key)(state) }), | |
{}, | |
); | |
export const connectWithState = (...stateKeys) => connect(getMapStateFor(stateKeys)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: