Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// redirect to path if predicate returns true
export default function redirect (path, predicate) {
return Component =>
class Composed extends React.Component {
componentWillMount () {
if (predicate(props))
redirectTo(path)
}
componentWillReceiveProps (nextProps) {
if (predicate(nextProps))
redirectTo(path)
}
render () {
return <Component {...this.props} />
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment