Created
June 15, 2018 22:40
-
-
Save abm0/bea2108ac269d7d7115df7be24e91356 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
import React, { Component } from 'react'; | |
export default function withPropsChecker(WrappedComponent) { | |
return class PropsChecker extends Component { | |
componentWillReceiveProps(nextProps) { | |
Object.keys(nextProps) | |
.filter(key => { | |
return nextProps[key] !== this.props[key]; | |
}) | |
.map(key => { | |
console.log( | |
'changed property:', | |
key, | |
'from', | |
this.props[key], | |
'to', | |
nextProps[key] | |
); | |
}); | |
} | |
render() { | |
return <WrappedComponent {...this.props} />; | |
} | |
}; | |
} | |
// Usage | |
withPropsChecker(MyComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment