Created
September 26, 2019 22:06
-
-
Save andregardi/6a0aa187c22817cb2513255cc3590d20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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