filtered_list : removed deprecated lifecycles and memoized dataSource (#4989)
* filtered_list: memoized dataSource instead of storing in a state * removed deprecated lifecycles * removed if
This commit is contained in:
parent
77bc6257ac
commit
47b62daccb
1 changed files with 6 additions and 7 deletions
|
|
@ -19,6 +19,7 @@ import {General} from '@mm-redux/constants';
|
|||
import {sortChannelsByDisplayName} from '@mm-redux/utils/channel_utils';
|
||||
import {displayUsername} from '@mm-redux/utils/user_utils';
|
||||
import {t} from '@utils/i18n';
|
||||
import memoize from 'memoize-one';
|
||||
|
||||
const VIEWABILITY_CONFIG = ListTypes.VISIBILITY_CONFIG_DEFAULTS;
|
||||
|
||||
|
|
@ -66,7 +67,6 @@ class FilteredList extends Component {
|
|||
};
|
||||
|
||||
this.state = {
|
||||
dataSource: this.buildData(props),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -331,13 +331,12 @@ class FilteredList extends Component {
|
|||
return sections;
|
||||
};
|
||||
|
||||
buildData = (props, term) => {
|
||||
buildData = memoize((props) => {
|
||||
if (!props.currentChannel) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.buildSectionsForSearch(props, term);
|
||||
};
|
||||
return this.buildSectionsForSearch(props, props.term);
|
||||
}, ([props], [prevProps]) => props.term === prevProps.term);
|
||||
|
||||
keyExtractor = (item) => item.id || item;
|
||||
|
||||
|
|
@ -378,8 +377,8 @@ class FilteredList extends Component {
|
|||
};
|
||||
|
||||
render() {
|
||||
const {testID, styles} = this.props;
|
||||
const {dataSource} = this.state;
|
||||
const {styles, testID} = this.props;
|
||||
const dataSource = this.buildData(this.props);
|
||||
return (
|
||||
<View
|
||||
testID={testID}
|
||||
|
|
|
|||
Loading…
Reference in a new issue