首页 > 解决方案 > 混淆了默认和命名导入?

问题描述

在我的 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>
            )
        }
    }

在此处输入图像描述

标签: javascriptfirebasereact-nativegoogle-cloud-firestore

解决方案


推荐阅读