// credit: https://github.com/facebook/fbjs/blob/main/packages/fbjs/src/core/shallowEqual.js export function shallowEqual(objA: any, objB: any) { if (Object.is(objA, objB)) { return true; } if ( typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null ) { return false; } const keysA = Object.keys(objA); const keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. for (const key of keysA) { if ( !Object.prototype.hasOwnProperty.call(objB, key) || !Object.is(objA[key], objB[key]) ) { return false; } } return true; } export const shallowUpdater = (newState: T) => (state: T | null): T => { if (state && shallowEqual(state, newState)) { return state; } return newState; };