diff --git a/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js b/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js index 3552c35fe..1cb49a896 100644 --- a/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js +++ b/app/components/sidebars/main/channels_list/filtered_list/filtered_list.js @@ -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 (