【发布时间】:2020-03-23 05:31:22
【问题描述】:
我正在尝试从 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 方法中打印。我需要用这些数据创建一个列表。
【问题讨论】:
-
你试过在 View 中使用 renderList 吗?
-
试过了,不行
-
很抱歉,您在渲染列表中没有返回任何内容。您从 map 函数创建了一个 JSX,但您还必须返回它。只需将 return 关键字放在帐户 && 后面 ...
-
是的,伙计。你是对的
-
如果你想了解 ES6 语法以及 JS 数组如何运作:reactdevstation.github.io/2020/03/18/es6-for-react.html
标签: firebase react-native redux-firestore