-
-
Save itzzmeakhi/37882001d37915a5d7ee1a966d6fdf46 to your computer and use it in GitHub Desktop.
This file contains 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
import React, { Component } from 'react'; | |
import { store } from './redux/store'; | |
const connectFn = (mapStateToProps, mapDispatchToProps) => { | |
return (WrappedComponent) => { | |
return class extends Component { | |
unsubscribeTheStore = null; | |
componentDidMount() { | |
this.unsubscribeTheStore = store.subscribe(this.handleStateChange); | |
} | |
componentWillUnmount() { | |
this.unsubscribeTheStore(); | |
} | |
handleStateChange = () => { | |
this.forceUpdate(); | |
} | |
render() { | |
return ( | |
<WrappedComponent | |
{...this.props} | |
{...mapStateToProps(store.getState(), this.props)} | |
{...mapDispatchToProps(store.dispatch, this.props)} | |
/> | |
); | |
} | |
} | |
} | |
} | |
export { connectFn }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment