Created
December 4, 2019 11:53
-
-
Save leonidkuznetsov18/f42e47e088934c04999c8798c3cf72d2 to your computer and use it in GitHub Desktop.
redux connect impementation
This file contains hidden or 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
| 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