Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. let oldProps = null;
  2. function shallowCompare (props){
  3. if(props !== oldProps) console.log(props);
  4. oldProps = props;
  5. }
  6.  
  7. const mary = { name: "mary", age: 20 };
  8. const john = { name: "john", age: 30 };
  9.  
  10. shallowCompare(mary) // prints -> { name: "mary", age: 20 }
  11. shallowCompare(john) // prints -> { name: "john", age: 30 }
  12.  
  13. john.age = 31;
  14. shallowCompare(john) // will not print!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement