Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

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