如何禁用基于数据库的页面(firebase)查询?

如何禁用基于数据库的页面(firebase)查询?,firebase,react-native,firebase-realtime-database,Firebase,React Native,Firebase Realtime Database,我是react和firebase的新手,目前正在开发和应用作为我最后一年的项目 问题: 我的应用程序中有两页,分别是第1页和第2页, 我想禁用第1页,直到输入第2页的数据为止(安装应用程序时应仅检查初始记录) 代码: 第1页内的代码 componentDidMount() { firebase.database().ref(`/users/${awcid}/Timeline/Page2/`) .orderByChild('Page2date') .limitToLast(1)

我是react和firebase的新手,目前正在开发和应用作为我最后一年的项目

问题:

我的应用程序中有两页,分别是第1页和第2页, 我想禁用第1页,直到输入第2页的数据为止(安装应用程序时应仅检查初始记录)

代码:

第1页内的代码

componentDidMount() {
firebase.database().ref(`/users/${awcid}/Timeline/Page2/`)
     .orderByChild('Page2date')
     .limitToLast(1)
     .once('value', checkifexists => {
       const datafff = firebaseLooper(checkifexists);
       console.log("checkifexists", datafff.length);
        const temp=datafff.length;
       if ((temp >= 1)) {
         this.setState({
           checkifexists: temp
         });
         console.log( "--------checkifexists--------","IF CONDITION",this.state.checkifexists, "----------------");
       } else {
         this.setState({
           checkifexists: 0
         });
         console.log("ELSE CONDITION");
       }
     });
}
内部渲染

{!(parseInt(this.state.checkifexists)>=parseInt(1))?
请首先进入股票页面以访问此页面{'\n'}
:
:显示表单}

此代码工作正常,但每次加载page1时都会进行检查(而不是最初检查)

您必须保留一个标志,以确定安装后应用程序是否第一次运行。您可以使用将字段存储为“isNotFrsttime”,并在第一次运行后将其设置为true。另外,请确保包含布尔检查,以仅在应用程序首次运行时阻止您的视图

或者,如果您正在使用redux,则可以在应用程序启动时保持redux状态并重新水合。如果您已经在项目中实现了redux,那么可以将您的标志存储在redux中

   {!(parseInt(this.state.checkifexists) >= parseInt(1)) ? 
 <View style={styles.notexists} >
<Text style={{ color: '#FFFFFF', textAlign: 'center', alignItems: 'center', }}>Please enter stock page initially to access this page{'\n'}</Text>
</View> :
         :<View><Text>Display the form</Text></View>}