首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React Native FlatList BUG?

React Native FlatList BUG?
EN

Stack Overflow用户
提问于 2017-11-22 11:43:31
回答 1查看 551关注 0票数 0

我想在FlatList中渲染一个页脚,但遇到了一些奇怪的问题:

代码语言:javascript
复制
 constructor(props) {
    super(props);
    // bind this for these 4 functions, cause FlatList footer can not be render
    this._renderFooter=this._renderFooter.bind(this)
    this._onEndReached=this._onEndReached.bind(this)
    this._separator = this._separator.bind(this)
}

FlatList:

代码语言:javascript
复制
<FlatList
    data={this.state.dataArray}
    renderItem={this._renderItemView}

    ListFooterComponent={this._renderFooter}
    onEndReached={this._onEndReached}
    onEndReachedThreshold={1}
    ItemSeparatorComponent={this._separator}
    // BUG here: above functions which has been bind this in component constructor, FlatList Footer would not render

    // // below functions called bind this here, FlatList Footer renders fun
    // ListFooterComponent={this._renderFooter.bind(this)}
    // onEndReached={this._onEndReached.bind(this)}
    // onEndReachedThreshold={1}
    // ItemSeparatorComponent={this._separator.bind(this)}
/>

如果我将所有这些函数绑定调用都放在构造函数中,FlatList就不能像预期的那样用_renderFooter函数呈现它的页脚。

演示项目:https://github.com/xilibro/ReactNativeFlatListDemo

EN

回答 1

Stack Overflow用户

发布于 2017-11-22 13:51:35

试一试

代码语言:javascript
复制
            ListFooterComponent={<Footer {...this.props}/>}

页脚的位置

代码语言:javascript
复制
    const RTFooter = (props) =>{
        return(
            <View>
                <Text>Hello</Text>
            </View>
        );
    };

    RTFooter.propTypes = {

    };

export default RTFooter;

页脚应为class

另一种选择是使用箭头函数(更好)

代码语言:javascript
复制
 renderFooter = () =>{
    return(<View/>);
    }

然后

代码语言:javascript
复制
 ListFooterComponent={this.renderFooter}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47426412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档