From 6b4b4ce75f5b09c7eb1aaa426ce93c03e40a2e48 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 25 Sep 2019 02:33:43 +0200 Subject: [PATCH] Null check on current (#3316) --- app/components/post_list/post_list.js | 4 ++-- app/components/post_list/post_list.test.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/components/post_list/post_list.js b/app/components/post_list/post_list.js index 588e8ae8c..fb5a9c7a6 100644 --- a/app/components/post_list/post_list.js +++ b/app/components/post_list/post_list.js @@ -299,7 +299,7 @@ export default class PostList extends PureComponent { scrollToBottom = () => { setTimeout(() => { - if (this.flatListRef?.current) { + if (this.flatListRef.current) { this.flatListRef.current.scrollToOffset({offset: 0, animated: true}); } }, 250); @@ -316,7 +316,7 @@ export default class PostList extends PureComponent { scrollToIndex = (index) => { this.animationFrameInitialIndex = requestAnimationFrame(() => { - if (this.flatListRef?.current && index > 0 && index <= this.getItemCount()) { + if (this.flatListRef.current && index > 0 && index <= this.getItemCount()) { this.flatListScrollToIndex(index); } }); diff --git a/app/components/post_list/post_list.test.js b/app/components/post_list/post_list.test.js index ffcf4e76b..fe7c684b7 100644 --- a/app/components/post_list/post_list.test.js +++ b/app/components/post_list/post_list.test.js @@ -64,7 +64,9 @@ describe('PostList', () => { const indexInRange = baseProps.postIds.length; const indexOutOfRange = [-1, indexInRange + 1]; - instance.flatListRef = {}; + instance.flatListRef = { + current: null, + }; instance.scrollToIndex(indexInRange); expect(flatListScrollToIndex).not.toHaveBeenCalled();