Skip to content

Instantly share code, notes, and snippets.

@coderitual
Created November 27, 2017 14:48
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 coderitual/92e91b1f2077163c167cc20f712fe61f to your computer and use it in GitHub Desktop.
Save coderitual/92e91b1f2077163c167cc20f712fe61f to your computer and use it in GitHub Desktop.
// 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