更新Flatlist,拉入刷新,警告:列表中的每个孩子都应该有一个唯一的“键”

谢谢你的帮助...

我正在尝试添加具有刷新功能的平面列表。

我发布到Firebase的操作和我的显示userPosts的平面列表在单独的配置文件屏幕上运行(通过自动更新redux状态更改,而不是拉动刷新)。

控制台记录“之前的所有帖子”和“之后的所有帖子”显示Firebase响应数组正在更新。就像现在的代码一样,当刷新被拉时,将弹出空白帖子,好像它知道已更新,但是值或格式未对齐。

任何帮助将不胜感激。再次感谢。 -马特

Warning: Each child in a list should have a unique "key" prop.%s%s See /fb.me/react-warning-keys for more information.%s, Check the render method of `VirtualizedList`.

动作:

//get first five posts
export const getPosts = () => {
    return async (dispatch) => {
        try {
            const posts = await Fire.shared.db.collection('posts').orderBy("timestamp", "desc").limit(5).get() //get all the posts'

            let array = []
            posts.forEach((post) => {
                array.push(post.data())
            })

            dispatch({ type: 'GET_POSTS', payload: array })
        } catch (e) {
            console.error(e)
        }
    }
}

//get additional posts
export const addPostsBefore = (getState) => {
    return async (dispatch, getState) => {
        try {
            console.log("array.allPosts before addPostsBefore: " + JSON.stringify(getState().feed.allPosts.length) )
            const posts = await Fire.shared.db.collection('posts').where('timestamp', '>=', getState().feed.allPosts[0].timestamp).orderBy("timestamp", "asc").limitToLast(10).get() 
            if (posts) {
                console.log("Firebase response to be added: " + posts )
                let array = []
                posts.forEach((post) => {
                    array.push(post.data())
                })
                console.log("array.length: " + array.length )
                dispatch({ type: 'TO_BE_ADDED', payload: array })
                console.log("array.allPosts after addPostsBefore: " + JSON.stringify(getState().feed.allPosts.length) )
            } else {
                return null
            }
        } catch (e) {
            console.error(e)
        }
    }
}

减速器:

let feedDefaultState = {}
const feed = (state = feedDefaultState, action) => {
     switch (action.type) {
        case 'TO_BE_ADDED':
            return {...state, allPosts: [action.payload, ...state.allPosts]}
        case 'GET_POSTS':
            return { ...state, allPosts: action.payload }
        default:
            return state
    }
}

屏幕/平面列表:

<FlatList
    data={this.props.feed.allPosts}
    onRefresh={this.handleRefresh}                        
    refreshing={false}                        
    keyExtractor={(item) => item.id}                        
    renderItem={({ item }) =>
    <View><Text>{item.postDescription}</Text></View>
    }                           
/>```