Created
November 27, 2017 14:48
-
-
Save coderitual/92e91b1f2077163c167cc20f712fe61f 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
// 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