Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Created July 6, 2017 09:05
Show Gist options
  • Save ernestofreyreg/46d6b03347f15b0c94cc8d955e375544 to your computer and use it in GitHub Desktop.
Save ernestofreyreg/46d6b03347f15b0c94cc8d955e375544 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react'
const connect = (component, actionCreator, initialState) => {
const attach = instance => ({
set: fn => new Promise(resolve => instance.setState(fn, resolve)),
get: () => instance.state
})
return class Connected extends Component {
constructor(props, context) {
super(props, context)
this.state = initialState
this.actions = actionCreator(attach(this))
}
render () {
return React.createElement(component, {...this.props,...this.actions, ...this.state})
}
}
}
export default connect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment