正在Firebase Cloud Firestore中显示数据,但是在代码中出现错误。无法理解问题是什么?
我尝试在新文件中使用导出默认值,而不是在RootStack中使用类,但是当我尝试这样做时也会收到错误消息。
export default class App extends React.Component {
render() {
return <RootStack />;
}
}
const RootStack = createStackNavigator(
{
Auth: {
screen: Auth, navigationOptions: { header: null },
},
Login: {
screen: Login, navigationOptions: { header: null },
},
Home: {
screen: Home, navigationOptions: { header: null },
},
}
);
class Home extends React.Component {
constructor(props){
super(props);
this.state = ({
todoTasks: []
})
this.ref = firestore.collection("tips");
}
componentDidMount() {
this.unsubscribe = this.ref.onSnapshot((querySnapshot) => {
const todos = [];
querySnapshot.forEach((doc) => {
todos.push({
tips: doc.data().tips
})
})
this.setState({
todoTask: todos
})
})
}
render() {
return (
<View>
<Flatlist
data={this.state.todoTask}
renderItem={({ item, index }) => {
return(
<Text>{item.tips}</Text>)
}}
>
</Flatlist>
</View>
)
}
}