我在React Native中有一个加载屏幕组件。每当Auth状态改变时,我都会导航到所需的屏幕。当用户正在注册时,我将redux状态标记为isRegistering = true。这是因为在使用firebase完成注册后,我仍然希望显示注册完成屏幕并根据身份验证状态暂停加载屏幕的自动导航。
问题似乎是在auth更改时调用事件时,redux状态为空。这是事件,我从调试中知道,redux状态之前有数据,并且它们在事件之后就有了它们。但是在事件和检查Redux中的isRegistration期间,状态完全为空(重置为默认状态)。
我检查了所有的动作,reducer等等。没有任何调用,在authstatechanged事件的那一刻,REDx声明只是被检查,那时它没有数据,eventho数据就在它之前。
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')
}
})
}