FilteredList, now being a controlled component does not need state

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/5718/head
Michael Telatynski 2018-01-25 21:06:35 +00:00
parent 04bca93e0d
commit 662a6297e7
No known key found for this signature in database
GPG Key ID: 3F879DA5AD802A5E
1 changed files with 3 additions and 12 deletions

View File

@ -252,24 +252,15 @@ class FilteredList extends React.Component {
constructor(props, context) {
super(props, context);
this.onQuery = this.onQuery.bind(this);
this.state = {
query: this.props.query,
};
}
componentWillReceiveProps(nextProps) {
if (this.state.query !== nextProps.query) this.setState({ query: nextProps.query });
}
onQuery(ev) {
this.setState({ query: ev.target.value });
if (this.props.onChange) this.props.onChange(ev.target.value);
}
filterChildren() {
if (this.state.query) {
const lowerQuery = this.state.query.toLowerCase();
if (this.props.query) {
const lowerQuery = this.props.query.toLowerCase();
return this.props.children.filter((child) => child.key.toLowerCase().includes(lowerQuery));
}
return this.props.children;
@ -279,7 +270,7 @@ class FilteredList extends React.Component {
return <div>
<input size="64"
onChange={this.onQuery}
value={this.state.query}
value={this.props.query}
placeholder={_t('Filter results')}
className="mx_TextInputDialog_input mx_DevTools_RoomStateExplorer_query" />
{ this.filterChildren() }