Skip to content

Instantly share code, notes, and snippets.

@mrblueblue
Created May 31, 2016 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrblueblue/d82f3a34620c8566cf3b8c4734ce01f9 to your computer and use it in GitHub Desktop.
Save mrblueblue/d82f3a34620c8566cf3b8c4734ce01f9 to your computer and use it in GitHub Desktop.
import {PropTypes} from 'react'
import {compose, getContext, mapProps} from 'recompose'
const noop = () => ({})
function connect(mapStateToProps = noop, mapDispatchToProps = noop) {
return compose(
getContext({
store: PropTypes.shape({
getState: PropTypes.func,
dispatch: PropTypes.func,
subscribe: PropTypes.func,
})
}),
mapProps(({store, ...rest}) => Object.assign(
{ },
{...rest},
mapStateToProps(store.getState(), {...rest}),
mapDispatchToProps(store.dispatch, {...rest})
))
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment