为什么反应本机地图功能无法正常工作?

时间:2020-03-23 05:31:22

标签: firebase react-native redux-firestore

我正在尝试从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方法中打印。我需要使用该数据创建一个列表。

1 个答案:

答案 0 :(得分:0)

请尝试:

    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()}
                </>
            )
        }

希望有帮助