Reputation: 1504
I have a loading screen component in React Native. Whenever Auth state changes, i navigate to the desired screen. When user is in process of registration i flag the redux state as isRegistering = true. This is because after registration is completed with firebase, i still want to show registration completed screen and hold off the automatic navigation from loading screen based on auth state.
The problem seems to be that when the event is called on auth change, the redux state is empty. That is eventho i know from debugging that the redux state had data before and it has them right after them event. But during the event and checking on isRegistration in Redux, the state is completely empty ( reset to default state ).
I checked on all my actions, reducer etc. There is nothing called, the redux stated is just being checked at the moment of authstatechanged event and at that moment it has no data, eventho the data were there right before it.
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
}
}
Upvotes: 0
Views: 994
Reputation: 626
Try this,
componentDidMount() {
var that = this;
firebase.auth().onAuthStateChanged(user => {
if (that.props.userObject.isRegistering === false) {
that.props.navigation.navigate(user ? 'MainScreen' : 'LandingPage')
}
})
}
Upvotes: 1