首页 > 解决方案 > 为什么反应原生地图功能无法正常工作?

问题描述

我正在尝试从 firebase firestore 检索数据。来自 firestore 的数据正在控制台上登录,但在我使用组件时不显示。

renderList = () => {
        const { accounts } = this.props
        accounts && accounts.map((account) => {
            return (
                <View>
                    <Text>{account.accountName}</Text>
                    {console.log(account.accountName)}
                </View>
            )
        })
    }

    render() {
        return (
            <>
                {this.renderList()}
            </>
        )
    }

在上面的编码中,console.log(account.accountName) 正在工作,但它没有在 render 方法中打印。我需要使用该数据创建一个列表。

标签: firebasereact-nativeredux-firestore

解决方案


请试试这个:

    renderList = () => {
            const { accounts } = this.props;
     if(accounts){
            return accounts.map((account) => {
                return (
                    <View>
                        <Text>{account.accountName}</Text>
                        {console.log(account.accountName)}
                    </View>
                )
            })
}
        }

        render() {
            return (
                <>
                    {this.renderList()}
                </>
            )
        }

希望能帮助到你


推荐阅读