From 46f9d44e640c0a8ff83e528e163aa15bce84f0e7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 24 Jul 2020 13:58:21 -0600 Subject: [PATCH] Use PureComponent instead It ranges wildly between 10 and 50ms while ours is stable at 30-40ms, but the effort doesn't need to be duplicated. --- src/components/views/rooms/RoomTile.tsx | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/components/views/rooms/RoomTile.tsx b/src/components/views/rooms/RoomTile.tsx index b7275e5074..259d2aa5b8 100644 --- a/src/components/views/rooms/RoomTile.tsx +++ b/src/components/views/rooms/RoomTile.tsx @@ -55,7 +55,6 @@ import {ActionPayload} from "../../../dispatcher/payloads"; import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore"; import { NotificationState } from "../../../stores/notifications/NotificationState"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; -import { objectDiff, objectHasValueChange } from "../../../utils/objects"; interface IProps { room: Room; @@ -110,7 +109,7 @@ const NotifOption: React.FC = ({active, onClick, iconClassNam ); }; -export default class RoomTile extends React.Component { +export default class RoomTile extends React.PureComponent { private dispatcherRef: string; private roomTileRef = createRef(); @@ -155,22 +154,6 @@ export default class RoomTile extends React.Component { MessagePreviewStore.instance.off(ROOM_PREVIEW_CHANGED, this.onRoomPreviewChanged); } - public shouldComponentUpdate(nextProps: Readonly, nextState: Readonly): boolean { - // Whenever a prop change happens (or our parent updates) we can get told to update too. Try - // to minimize that by seeing if anything actually changed. - if (objectHasValueChange(this.props, nextProps)) { - return true; - } - - // Do the same for state - if (objectHasValueChange(this.state, nextState)) { - return true; - } - - // Finally, nothing changed so say so. - return false; - } - private onAction = (payload: ActionPayload) => { if (payload.action === "view_room" && payload.room_id === this.props.room.roomId && payload.show_room_tile) { setImmediate(() => {