React-Native another VirtualizedList-backed container

后端 未结 15 794
名媛妹妹
名媛妹妹 2020-12-08 13:00

After upgrading to react-native 0.61 i get a lot of warnings like that:

VirtualizedLists should never be nested inside plain ScrollViews with the same orient         


        
15条回答
  •  情歌与酒
    2020-12-08 13:37

    Just in case this helps someone, this is how I fixed the error in my case.

    I had a FlatList nested inside a ScrollView:

    render() {
        return (
            
                {'My Title'}
                 {
                        return 

    {item.name}

    ; }} /> {this.state.loading && {'Loading...'}}
    ); }

    and I got rid of the ScrollView by using the FlatList to render everything I needed, which got rid of the warning:

    render() {
        const getHeader = () => {
            return {'My Title'};
        };
    
        const getFooter = () => {
            if (this.state.loading) {
                return null;
            }
            return {'Loading...'};
        };
    
        return (
             {
                    return 

    {item.name}

    ; }} ListHeaderComponent={getHeader} ListFooterComponent={getFooter} /> ); }

提交回复
热议问题