run autocomplete after mounting

componentWillReceiveProps doesn't run after mount,
and is deprecated as well.

Update state after both on componentDidMount and componentDidUpdate
pull/21833/head
Bruno Windels 2019-05-09 14:57:09 +02:00
parent a2f1f49972
commit a765fdf98a
1 changed files with 11 additions and 6 deletions

View File

@ -60,18 +60,22 @@ export default class Autocomplete extends React.Component {
};
}
componentWillReceiveProps(newProps, state) {
if (this.props.room.roomId !== newProps.room.roomId) {
componentDidMount() {
this._applyNewProps();
}
_applyNewProps(oldQuery, oldRoom) {
if (oldRoom && this.props.room.roomId !== oldRoom.roomId) {
this.autocompleter.destroy();
this.autocompleter = new Autocompleter(newProps.room);
this.autocompleter = new Autocompleter(this.props.room);
}
// Query hasn't changed so don't try to complete it
if (newProps.query === this.props.query) {
if (oldQuery === this.props.query) {
return;
}
this.complete(newProps.query, newProps.selection);
this.complete(this.props.query, this.props.selection);
}
componentWillUnmount() {
@ -233,7 +237,8 @@ export default class Autocomplete extends React.Component {
}
}
componentDidUpdate() {
componentDidUpdate(prevProps) {
this._applyNewProps(prevProps.query, prevProps.room);
// this is the selected completion, so scroll it into view if needed
const selectedCompletion = this.refs[`completion${this.state.selectionOffset}`];
if (selectedCompletion && this.container) {