Make sure list has mounted before using ref

This commit is contained in:
Ken-Håvard Lieng 2018-10-26 08:18:31 +02:00
parent 4482dd33ce
commit 38ed5a367b
2 changed files with 12 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,14 +6,16 @@ import UserListItem from './UserListItem';
export default class UserList extends PureComponent { export default class UserList extends PureComponent {
getSnapshotBeforeUpdate(prevProps) { getSnapshotBeforeUpdate(prevProps) {
const { users } = this.props; if (this.list.current) {
const { users } = this.props;
if (prevProps.users.length !== users.length) { if (prevProps.users.length !== users.length) {
this.list.current.resetAfterIndex( this.list.current.resetAfterIndex(
Math.min(prevProps.users.length, users.length) + 1 Math.min(prevProps.users.length, users.length) + 1
); );
} else { } else {
this.list.current.forceUpdate(); this.list.current.forceUpdate();
}
} }
return null; return null;