Skip to content

Instantly share code, notes, and snippets.

@Jahans3
Last active December 5, 2018 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jahans3/f346b09af7ebdf2de369e7550844156c to your computer and use it in GitHub Desktop.
Save Jahans3/f346b09af7ebdf2de369e7550844156c to your computer and use it in GitHub Desktop.
Shallow compare
function shallowCompare (state, nextState) {
if ((typeof state !== 'object' || state === null || typeof nextState !== 'object' || nextState === null)) return false;
return Object.entries(nextState).reduce((shouldUpdate, [key, value]) => state[key] !== value ? true : shouldUpdate, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment