Skip to content

Instantly share code, notes, and snippets.

@chrisabrams
Created May 1, 2018 14:05
Show Gist options
  • Save chrisabrams/d2152ab98613ac4b9a1fdf20bfb5a34b to your computer and use it in GitHub Desktop.
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
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