From e214039cee42ec46293b98fbc9cc1d4abf431366 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Tue, 23 Jul 2019 20:26:39 +0200 Subject: [PATCH] Call scrollToIndex only if flatListRef.current is not null (#3023) --- app/components/post_list/post_list.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/components/post_list/post_list.js b/app/components/post_list/post_list.js index b7bf7fee5..693817a82 100644 --- a/app/components/post_list/post_list.js +++ b/app/components/post_list/post_list.js @@ -291,16 +291,17 @@ export default class PostList extends PureComponent { width > 0 && height > 0 && this.props.initialIndex > 0 && - !this.hasDoneInitialScroll && - this.flatListRef?.current + !this.hasDoneInitialScroll ) { requestAnimationFrame(() => { - this.flatListRef.current.scrollToIndex({ - animated: false, - index: this.props.initialIndex, - viewOffset: 0, - viewPosition: 1, // 0 is at bottom - }); + if (this.flatListRef?.current) { + this.flatListRef.current.scrollToIndex({ + animated: false, + index: this.props.initialIndex, + viewOffset: 0, + viewPosition: 1, // 0 is at bottom + }); + } }); this.hasDoneInitialScroll = true; }