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.
This commit is contained in:
parent
e3800dba0e
commit
46f9d44e64
1 changed files with 1 additions and 18 deletions
|
@ -55,7 +55,6 @@ import {ActionPayload} from "../../../dispatcher/payloads";
|
||||||
import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore";
|
import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore";
|
||||||
import { NotificationState } from "../../../stores/notifications/NotificationState";
|
import { NotificationState } from "../../../stores/notifications/NotificationState";
|
||||||
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
||||||
import { objectDiff, objectHasValueChange } from "../../../utils/objects";
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
room: Room;
|
room: Room;
|
||||||
|
@ -110,7 +109,7 @@ const NotifOption: React.FC<INotifOptionProps> = ({active, onClick, iconClassNam
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class RoomTile extends React.Component<IProps, IState> {
|
export default class RoomTile extends React.PureComponent<IProps, IState> {
|
||||||
private dispatcherRef: string;
|
private dispatcherRef: string;
|
||||||
private roomTileRef = createRef<HTMLDivElement>();
|
private roomTileRef = createRef<HTMLDivElement>();
|
||||||
|
|
||||||
|
@ -155,22 +154,6 @@ export default class RoomTile extends React.Component<IProps, IState> {
|
||||||
MessagePreviewStore.instance.off(ROOM_PREVIEW_CHANGED, this.onRoomPreviewChanged);
|
MessagePreviewStore.instance.off(ROOM_PREVIEW_CHANGED, this.onRoomPreviewChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
public shouldComponentUpdate(nextProps: Readonly<IProps>, nextState: Readonly<IState>): 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) => {
|
private onAction = (payload: ActionPayload) => {
|
||||||
if (payload.action === "view_room" && payload.room_id === this.props.room.roomId && payload.show_room_tile) {
|
if (payload.action === "view_room" && payload.room_id === this.props.room.roomId && payload.show_room_tile) {
|
||||||
setImmediate(() => {
|
setImmediate(() => {
|
||||||
|
|
Loading…
Reference in a new issue