Created
May 1, 2018 14:05
-
-
Save chrisabrams/d2152ab98613ac4b9a1fdf20bfb5a34b to your computer and use it in GitHub Desktop.
Idea around cleaning up the boilerplate code for connect decorator between React.Component -> Redux.Reducer
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' | |
export default function onConnect(keys) { | |
const mapStateToProps = (state) => { | |
const o = {} | |
for(let i = 0, l = keys.length; i < l; i++) { | |
const key = keys[i] | |
switch(key) { | |
case 'user': | |
o.user = state.userProvider | |
break | |
} | |
} | |
return o | |
} | |
return connect(mapStateToProps) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment