我是个新手,我使用react firebase redux,如何显示返回对象的问题数组,实现此目的的最佳方法是什么?我想像列表一样返回它们:
import { compose, withHandlers,withProps } from 'recompose'
import { firebaseConnect } from 'react-redux-firebase'
import { Alerts,spinnerWhileLoading } from '@components'
import { connect } from 'react-redux'
export default compose(
firebaseConnect([
{ type: 'once', path: '/questions' }
]),
withHandlers({
logout: ({ firebase }) => () =>
firebase.logout().catch(err => Alerts.danger(err.message))
}),
connect((state, props) => ({
questions: state.firebase.data.questions,
// questions return Object {
"-LrP3EkfZ8fCgkNycJ2-": Object {
"question": "De déféré déféré",
"user": "9jNkvzr0chgPi0SC6rXMlVWdOF12",
},
"-LrP4P3fQDK6DnS1hxDt": Object {
"question": "De déféré déféré",
"user": "9jNkvzr0chgPi0SC6rXMlVWdOF12",
},
"-LrPNX18hQLL-OjHWC3R": Object {
"question": "Dddededed",
"user": "9jNkvzr0chgPi0SC6rXMlVWdOF12",
},
}
})),
spinnerWhileLoading(['questions'])
)
到我的index.js:
let Questions = ({ navigation: { navigate }, logout,questions}) => (
<View style={{flex: 1}}>
{console.log(questions)}
//question array
<li question ="" />
<li question ="" />
//question array
</View>
export default enhancer(Questions)
答案 0 :(得分:0)
如果我理解您应该:
not
query.onSnapshot(querySnapshot => {
let arrayToReturn = [];
querySnapshot.forEach(doc => {
const objectData = {
id: doc.id,
...doc.data()
};
arrayToReturn.push(objectData);
});
return arrayToReturn;
You will have array like this:
[
{
"id": "-LrP3EkfZ8fCgkNycJ2-"
"question": "De déféré déféré",
"user": "9jNkvzr0chgPi0SC6rXMlVWdOF12"
},
...
]
。让我知道它是否对您有帮助:)