Skip to content

Instantly share code, notes, and snippets.

@developit
Last active July 18, 2016 12:19
Show Gist options
  • Select an option

  • Save developit/569fe404e18b936ea42b3aa245b4d94a to your computer and use it in GitHub Desktop.

Select an option

Save developit/569fe404e18b936ea42b3aa245b4d94a to your computer and use it in GitHub Desktop.
function shallowEqual(a, b) {
if (a!==b) {
for (let i in a) if (a[i]!==b[i]) return false;
for (let i in b) if (!(i in a)) return false;
}
return true;
}
export function shouldComponentUpdate(props, state) {
return !shallowEqual(props, this.props) || !shallowEqual(state, this.state);
}
export default { shouldComponentUpdate };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment