Null check on current (#3316)

This commit is contained in:
Mattermost Build 2019-09-25 02:33:43 +02:00 committed by Miguel Alatzar
parent cdc020fc9c
commit 6b4b4ce75f
2 changed files with 5 additions and 3 deletions

View file

@ -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);
}
});

View file

@ -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();