Object.is() In Zustand's Source Code Explained
Object.is() method determines if two values are the same value, not reference. Used in Zustand's setState to check for true differences before updating state and notifying listeners.
In this article, we will explore how Object.is() method is used in Zustand’s source code. The above code snippet is picked from vanilla.ts Object.is() method is used in setState (more articles on this later on). Let’s first understand what an Object.is() method is. Object.is() The Object.is() static method determines whether two values are the same value. The below example is picked from MDN Docs: console.log(Object.is('1', 1)); // Expected output: false console.log(Object.is(NaN, NaN)); // Expected output: true console.log(Object.is(-0, 0)); // Expected ou...