SHARE
TWEET

Untitled

a guest Oct 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top