Skip to content

Instantly share code, notes, and snippets.

@andregardi
Created September 26, 2019 22:06
Show Gist options
  • Select an option

  • Save andregardi/6a0aa187c22817cb2513255cc3590d20 to your computer and use it in GitHub Desktop.

Select an option

Save andregardi/6a0aa187c22817cb2513255cc3590d20 to your computer and use it in GitHub Desktop.
let oldProps = null;
function shallowCompare (props){
if(props !== oldProps) console.log(props);
oldProps = props;
}
const mary = { name: "mary", age: 20 };
const john = { name: "john", age: 30 };
shallowCompare(mary) // prints -> { name: "mary", age: 20 }
shallowCompare(john) // prints -> { name: "john", age: 30 }
john.age = 31;
shallowCompare(john) // will not print!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment