Avoid unnecessary re-render on CHECK_NETWORK_STATUS

This commit is contained in:
Evan Hahn 2020-12-15 19:57:34 -06:00 committed by Josh Perez
parent b70b7a2cee
commit 55091edefa
3 changed files with 138 additions and 3 deletions

View file

@ -3,6 +3,7 @@
import { SocketStatus } from '../../types/SocketStatus';
import { trigger } from '../../shims/events';
import { assignWithNoUnnecessaryAllocation } from '../../util/assignWithNoUnnecessaryAllocation';
// State
@ -89,11 +90,12 @@ export function reducer(
if (action.type === CHECK_NETWORK_STATUS) {
const { isOnline, socketStatus } = action.payload;
return {
...state,
// This action is dispatched frequently. We avoid allocating a new object if nothing
// has changed to avoid an unnecessary re-render.
return assignWithNoUnnecessaryAllocation(state, {
isOnline,
socketStatus,
};
});
}
if (action.type === CLOSE_CONNECTING_GRACE_PERIOD) {