Created
March 15, 2016 20:16
-
-
Save yamadapc/e93786fb0e7ba8318ef8 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 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