Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Created March 10, 2018 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faceyspacey/0b8fd8ba4303271cbab4f503708bf13c to your computer and use it in GitHub Desktop.
Save faceyspacey/0b8fd8ba4303271cbab4f503708bf13c to your computer and use it in GitHub Desktop.
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