Guest User

Untitled

a guest
Oct 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. const withPropsChanged = (arePropsChagned, callback) => BaseComponent => {
  2. const factory = React.createFactory(BaseComponent)
  3. return class Watcher extends React.Component {
  4. componentWillReceiveProps(nextProps) {
  5. if (arePropsChagned(this.props, nextProps)) {
  6. callback(nextProps)
  7. }
  8. }
  9. render() {
  10. return factory(this.props)
  11. }
  12. }
  13. }
  14. // usage
  15.  
  16. withPropsChanged(
  17. (props, nextProps) =>
  18. props.path != nextProps.path,
  19. props => props.selectItem(null)
  20. ),
Add Comment
Please, Sign In to add comment