Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save misha-erm/955ec4a6a893cc3a19301872b3b7af6e to your computer and use it in GitHub Desktop.
Save misha-erm/955ec4a6a893cc3a19301872b3b7af6e to your computer and use it in GitHub Desktop.
Determine which props causes React components to re-render
import React from 'react';
export default function withPropsChecker(WrappedComponent) {
return class PropsChecker extends React.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