Skip to content

Instantly share code, notes, and snippets.

@leonidkuznetsov18
Created December 4, 2019 11:53
Show Gist options
  • Select an option

  • Save leonidkuznetsov18/f42e47e088934c04999c8798c3cf72d2 to your computer and use it in GitHub Desktop.

Select an option

Save leonidkuznetsov18/f42e47e088934c04999c8798c3cf72d2 to your computer and use it in GitHub Desktop.
redux connect impementation
function connect(mapStateToProps, mapDispatchToProps) {
return function(WrappedComponent) {
return class extends React.Component {
constructor() {
const { store } = this.context;
this.unsubcribe = store.subcribe(this.handleChange)
}
componentWillUnmount() {
this.unsubcribe()
}
handleChange = () => {
this.forceUpdate()
}
render() {
return(
<WrappedComponent
{...this.props}
{...mapStateToProps(store.getState, this.props)}
{...mapDispatchToProps(store.dispatch, this.props)}
/>
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment