Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Use componentDidMount in place of componentWillMount where possible
Browse files Browse the repository at this point in the history
This fixes a common React warning we see. Most of these components should be using constructors instead, however componentDidMount is just as good (and doesn't require converting most of these).

Conversion to classes will be done in a later stage of React warning fixes.

For element-hq/element-web#12877
  • Loading branch information
turt2live committed Mar 31, 2020
1 parent 56dda38 commit 3f99332
Show file tree
Hide file tree
Showing 70 changed files with 73 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/AsyncWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
// XXX: temporary logging to try to diagnose
// https://github.com/vector-im/riot-web/issues/3148
Expand Down
2 changes: 1 addition & 1 deletion src/async-components/views/dialogs/EncryptedEventDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default createReactClass({
return { device: null };
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
const client = MatrixClientPeg.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default class ManageEventIndexDialog extends React.Component {
}
}

async componentWillMount(): void {
async componentDidMount(): void {
let eventIndexSize = 0;
let crawlingRoomsCount = 0;
let roomCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/CustomRoomTagPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CustomRoomTagPanel extends React.Component {
};
}

componentWillMount() {
componentDidMount() {
this._tagStoreToken = CustomRoomTagStore.addListener(() => {
this.setState({tags: CustomRoomTagStore.getSortedTags()});
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/EmbeddedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class EmbeddedPage extends React.PureComponent {
return sanitizeHtml(_t(s));
}

componentWillMount() {
componentDidMount() {
this._unmounted = false;

if (!this.props.url) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/GroupView.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
this._matrixClient = MatrixClientPeg.get();
this._matrixClient.on("Group.myMembership", this._onGroupMyMembership);
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/LeftPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const LeftPanel = createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this.focusedElement = null;

this._breadcrumbsWatcherRef = SettingsStore.watchSetting(
Expand Down
4 changes: 1 addition & 3 deletions src/components/structures/MatrixChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default createReactClass({
return {serverConfig: props};
},

componentWillMount: function() {
componentDidMount: function() {
SdkConfig.put(this.props.config);

// Used by _viewRoom before getting state from sync
Expand Down Expand Up @@ -261,9 +261,7 @@ export default createReactClass({

this._accountPassword = null;
this._accountPasswordTimer = null;
},

componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction);
this._themeWatcher = new ThemeWatcher();
this._themeWatcher.start();
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/MyGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default createReactClass({
contextType: MatrixClientContext,
},

componentWillMount: function() {
componentDidMount: function() {
this._fetch();
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/RightPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class RightPanel extends React.Component {
}
}

componentWillMount() {
componentDidMount() {
this.dispatcherRef = dis.register(this.onAction);
const cli = this.context;
cli.on("RoomState.members", this.onRoomStateMember);
Expand Down
4 changes: 1 addition & 3 deletions src/components/structures/RoomDirectory.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
this.nextBatch = null;
this.filterTimeout = null;
Expand Down Expand Up @@ -89,9 +89,7 @@ export default createReactClass({
),
});
});
},

componentDidMount: function() {
this.refreshRoomList();
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/RoomStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
MatrixClientPeg.get().on("sync", this.onSyncStateChange);
MatrixClientPeg.get().on("Room.localEchoUpdated", this._onRoomLocalEchoUpdated);

Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/TagPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const TagPanel = createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this.unmounted = false;
this.context.on("Group.myMembership", this._onGroupMyMembership);
this.context.on("sync", this._onClientSync);
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/UserView.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class UserView extends React.Component {
this.state = {};
}

componentWillMount() {
componentDidMount() {
if (this.props.userId) {
this._loadProfileInfo();
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/ForgotPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this.reset = null;
this._checkServerLiveliness(this.props.serverConfig);
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;

// map from login step type to a function which will render a control
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/PostRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
// There is some assymetry between ChangeDisplayName and ChangeAvatar,
// as ChangeDisplayName will auto-get the name but ChangeAvatar expects
// the URL to be passed to you (because it's also used for room avatars).
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/Registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
this._replaceClient();
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/auth/CountryDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class CountryDropdown extends React.Component {
};
}

componentWillMount() {
componentDidMount() {
if (!this.props.value) {
// If no value is given, we start with the default
// country selected, but our parent component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export const MsisdnAuthEntry = createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._submitUrl = null;
this._sid = null;
this._msisdn = null;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/avatars/MemberStatusMessageAvatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class MemberStatusMessageAvatar extends React.Component {
this._button = createRef();
}

componentWillMount() {
componentDidMount() {
if (this.props.member.userId !== MatrixClientPeg.get().getUserId()) {
throw new Error("Cannot use MemberStatusMessageAvatar on anyone but the logged in user");
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/context_menus/MessageContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
MatrixClientPeg.get().on('RoomMember.powerLevel', this._checkPermissions);
this._checkPermissions();
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/context_menus/RoomTileContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class StatusMessageContextMenu extends React.Component {
};
}

componentWillMount() {
componentDidMount() {
const { user } = this.props;
if (!user) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/ConfirmUserActionDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default createReactClass({
askReason: false,
}),

componentWillMount: function() {
componentDidMount: function() {
this._reasonField = null;
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/RoomSettingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class RoomSettingsDialog extends React.Component {
onFinished: PropTypes.func.isRequired,
};

componentWillMount() {
componentDidMount() {
this._dispatcherRef = dis.register(this._onAction);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/RoomUpgradeDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default createReactClass({
onFinished: PropTypes.func.isRequired,
},

componentWillMount: async function() {
componentDidMount: async function() {
const recommended = await this.props.room.getRecommendedVersion();
this._targetVersion = recommended.version;
this.setState({busy: false});
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/dialogs/SetPasswordDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export default createReactClass({
};
},

componentWillMount: function() {
console.info('SetPasswordDialog component will mount');
componentDidMount: function() {
console.info('SetPasswordDialog component did mount');
},

_onPasswordChanged: function(res) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/ShareDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class ShareDialog extends React.Component {
});
}

componentWillMount() {
componentDidMount() {
if (this.props.target instanceof Room) {
const permalinkCreator = new RoomPermalinkCreator(this.props.target);
permalinkCreator.load();
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/dialogs/UnknownDeviceDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default createReactClass({
onSend: PropTypes.func.isRequired,
},

componentWillMount: function() {
componentDidMount: function() {
MatrixClientPeg.get().on("deviceVerificationChanged", this._onDeviceVerificationChanged);
},

Expand Down
4 changes: 1 addition & 3 deletions src/components/views/elements/AppTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,12 @@ export default class AppTile extends React.Component {
return false;
}

componentWillMount() {
componentDidMount() {
// Only fetch IM token on mount if we're showing and have permission to load
if (this.props.show && this.state.hasPermissionToLoad) {
this.setScalarToken();
}
}

componentDidMount() {
// Widget action listeners
this.dispatcherRef = dis.register(this._onAction);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/DeviceVerifyButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
const cli = MatrixClientPeg.get();
cli.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/EditableTextContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class EditableTextContainer extends React.Component {
this._onValueChanged = this._onValueChanged.bind(this);
}

componentWillMount() {
componentDidMount() {
if (this.props.getInitialValue === undefined) {
// use whatever was given in the initialValue property.
return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/LanguageDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class LanguageDropdown extends React.Component {
};
}

componentWillMount() {
componentDidMount() {
languageHandler.getAllLanguagesFromJson().then((langs) => {
langs.sort(function(a, b) {
if (a.label < b.label) return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/PersistentApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate);
ActiveWidgetStore.on('update', this._onActiveWidgetStoreUpdate);
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/Pill.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const Pill = createReactClass({
this.setState({resourceId, pillType, member, group, room});
},

componentWillMount() {
componentDidMount() {
this._unmounted = false;
this._matrixClient = MatrixClientPeg.get();
this.componentWillReceiveProps(this.props);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/PowerSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._initStateFromProps(this.props);
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/views/elements/ReplyThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default class ReplyThread extends React.Component {
ref={ref} permalinkCreator={permalinkCreator} />;
}

componentWillMount() {
componentDidMount() {
this.unmounted = false;
this.room = this.context.getRoom(this.props.parentEv.getRoomId());
this.room.on("Room.redaction", this.onRoomRedaction);
Expand Down
4 changes: 1 addition & 3 deletions src/components/views/elements/TintableSvg.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ const TintableSvg = createReactClass({
idSequence: 0,
},

componentWillMount: function() {
componentDidMount: function() {
this.fixups = [];
},

componentDidMount: function() {
this.id = TintableSvg.idSequence++;
TintableSvg.mounts[this.id] = this;
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/groups/GroupMemberInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default createReactClass({
};
},

componentWillMount: function() {
componentDidMount: function() {
this._unmounted = false;
this._initGroupStore(this.props.groupId);
},
Expand Down
Loading

0 comments on commit 3f99332

Please sign in to comment.