Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. export default function withPropsChecker(WrappedComponent) {
  4. return class PropsChecker extends React.Component {
  5. componentWillReceiveProps(nextProps) {
  6. Object.keys(nextProps)
  7. .filter(key => {
  8. return nextProps[key] !== this.props[key];
  9. })
  10. .map(key => {
  11. console.log(
  12. 'changed property:',
  13. key,
  14. 'from',
  15. this.props[key],
  16. 'to',
  17. nextProps[key]
  18. );
  19. });
  20. }
  21. render() {
  22. return <WrappedComponent {...this.props} />;
  23. }
  24. };
  25. }
  26.  
  27. // Usage
  28. withPropsChecker(MyComponent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement