Skip to content

Instantly share code, notes, and snippets.

@yamadapc
Created March 15, 2016 20:16
Show Gist options
  • Save yamadapc/e93786fb0e7ba8318ef8 to your computer and use it in GitHub Desktop.
Save yamadapc/e93786fb0e7ba8318ef8 to your computer and use it in GitHub Desktop.
import Component from 'react-pure-render/component';
import React from 'react';
import each from 'lodash/each';
import shouldPureComponentUpdate from 'react-pure-render/function';
export default function logComponentUpdates(Wrapped) {
return class Wrapper extends Component {
shouldComponentUpdate(nextProps, nextState) {
const should = shouldPureComponentUpdate.call(this, nextProps, nextState);
if (should) {
each(nextProps, (value, key) => {
if (value !== this.props[key]) {
console.log(`[logComponentUpdates] !! ${key} has changed?`, value, this.props[key]); // eslint-disable-line no-console, max-len
}
});
}
return should;
}
render() {
return (
<Wrapped {...this.props} />
);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment