我能够使Infinite Scroll与React Native和Firebase一起使用,但是在检索接下来的6个文档时存在一个问题(限制设置为6)。一旦刷新列表的末尾,它将返回另一个6,但这是将相同的6个文档附加到先前的相同6个文档中。
每次渲染6条记录时,我都会增加startAt,并且startAt将以正确的数量增加。不知道我是否缺少某些东西,或者它可能是异步问题?
// Imports: Dependencies
import React, { Component } from "react";
import { ActivityIndicator, Dimensions, FlatList, View, SafeAreaView, StyleSheet } from 'react-native';
import * as firebase from 'firebase';
import 'firebase/firestore';
import firebaseConfig from '../config/config';
// Imports: Components
import UserSelector from '../components/UserSelector';
import TitleLarge from '../components/TitleLarge';
// Screen Dimensions
const { height, width } = Dimensions.get('window');
// Screen: Flat List (Users)
class FlatListUsers extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
startAt: 0,
limit: 6,
loading: false,
};
}
// Component Will Mount
componentWillMount = () => {
// Firebase: Initialize
firebase.initializeApp({
apiKey: `${firebaseConfig.apiKey}`,
authDomain: `${firebaseConfig.authDomain}`,
databaseURL: `${firebaseConfig.databaseURL}`,
projectId: `${firebaseConfig.projectId}`,
storageBucket: `${firebaseConfig.storageBucket}`,
messagingSenderId: `${firebaseConfig.messagingSenderId}`,
});
}
// Component Did Mount
componentDidMount = () => {
this.retrieveUsers();
}
// Retrieve Users
retrieveUsers = async () => {
try {
// Set State: Loading
this.setState({ loading: true });
// Firebase: Database + Settings
const db = firebase.firestore();
// Query
console.log('Fetching Users')
const query = await db.collection('users')
.where('company', '==', 'Google')
.orderBy('first_name')
.startAt(this.state.startAt)
.limit(this.state.limit);
// Query Snapshot
const querySnapshot = await query.get();
拉丁的传说
慕哥9229398
相关分类