簡體   English   中英

Firebase onAuthStateChanged和Redux狀態

[英]Firebase onAuthStateChanged and Redux state

我在React Native中有一個加載屏幕組件。 每當“身份驗證”狀態更改時,我都會導航到所需的屏幕。 當用戶正在注冊時,我將redux狀態標記為isRegistering = true。 這是因為在使用Firebase完成注冊后,我仍然想顯示注冊完成屏幕,並根據身份驗證狀態從加載屏幕中停止自動導航。

問題似乎是當在auth change上調用事件時,redux狀態為空。 那是事件,我從調試中知道redux狀態之前有數據,事件發生后立即有數據。 但是在事件期間並在Redux中檢查isRegistration時,狀態完全為空(重置為默認狀態)。

我檢查了我所有的動作,reducer等。沒有任何調用, 只是在authstatechanged事件發生時檢查了redux聲明,那時它沒有數據,如果有數據就在它之前。

componentDidMount() {
        firebase.auth().onAuthStateChanged(user => {            
            if (this.props.userObject.isRegistering === false) {                
                this.props.navigation.navigate(user ? 'MainScreen' : 'LandingPage')
            }
        })
    }

const mapStateToProps = (state) => {   
    return {
        userObject: state.user
    }
}

嘗試這個,

componentDidMount() {
     var that = this;
        firebase.auth().onAuthStateChanged(user => {            
            if (that.props.userObject.isRegistering === false) {                
                that.props.navigation.navigate(user ? 'MainScreen' : 'LandingPage')
            }
        })
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM