Created
March 10, 2018 12:49
-
-
Save faceyspacey/0b8fd8ba4303271cbab4f503708bf13c 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
export default function connectAdvanced(selectorFactory, options) { | |
return function wrapWithConnect(WrappedComponent) { | |
class Connect extends Component { | |
static contextConsumers = [ReactReduxContext.Consumer] | |
static getDerivedStateFromProps(nextProps, [context], prevState) { | |
const { dispatch, state } = context | |
return this.selector(dispatch, state, nextProps, prevState) // returns `null` if no changes | |
} | |
addExtraProps(props) {/* the usual */} | |
render() { | |
return createElement(WrappedComponent, this.addExtraProps(this.state)) // <-- | |
} | |
} | |
Connect.WrappedComponent = WrappedComponent | |
return hoistStatics(Connect, WrappedComponent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment