Javascript 为什么远程调试未激活时“我的用户”为空,而激活时为对象?
当我远程使用调试js时,我的用户为非null;当我不远程使用调试js时,我的用户为null。 以下是我的代码,用于检查用户是否已登录,然后将其定向到正确的组件:Javascript 为什么远程调试未激活时“我的用户”为空,而激活时为对象?,javascript,reactjs,firebase,react-native,firebase-authentication,Javascript,Reactjs,Firebase,React Native,Firebase Authentication,当我远程使用调试js时,我的用户为非null;当我不远程使用调试js时,我的用户为null。 以下是我的代码,用于检查用户是否已登录,然后将其定向到正确的组件: componentDidMount(){ that=this; this.authSubscription = firebaseRef.auth().onAuthStateChanged((user) => { if (user) { firebaseRef.database().ref('/users/'+user.ui
componentDidMount(){
that=this;
this.authSubscription = firebaseRef.auth().onAuthStateChanged((user) => {
if (user) {
firebaseRef.database().ref('/users/'+user.uid+'/info').once('value').then(function(snapshot) {
if (snapshot.val() !== null) {
that.setState({
haveInfo: true,
loading: false,
user: true,
})
}else{
this.setState({
loading: false,
user: true,
haveInfo: false,
})
}
});
}else{
that.setState({
user: false,
haveInfo: false,
loading: false,
});
}
});
}
render() {
if (this.state.loading) {
//Welcome screen
return <Welcome />
}
if (this.state.user) {
if (this.state.haveInfo) {
//the user set up his info
return <Main />
}else{
//If the user didnt set up his info
return <ProfileSettingUp />
}
}
// If the user is null
return <MainLogToSignUpProceses />
componentDidMount(){
那=这个;
this.authSubscription=firebaseRef.auth().onAuthStateChanged((用户)=>{
如果(用户){
firebaseRef.database().ref('/users/'+user.uid+'/info')。一次('value')。然后(函数(快照){
如果(snapshot.val()!==null){
那是一个州({
haveInfo:是的,
加载:false,
用户:是的,
})
}否则{
这是我的国家({
加载:false,
用户:是的,
haveInfo:false,
})
}
});
}否则{
那是一个州({
用户:错,
haveInfo:false,
加载:false,
});
}
});
}
render(){
if(this.state.loading){
//欢迎屏幕
返回
}
if(this.state.user){
if(this.state.haveInfo){
//用户设置了他的信息
返回
}否则{
//如果用户没有设置他的信息
返回
}
}
//如果用户为空
返回
}
我不知道为什么会这样。
谢谢您的帮助。好吧,我无法直接从您的代码中回答您的问题,但是,您应该知道,当您启用远程js调试时,您使用的是浏览器的js运行时,而不是移动运行时。因此,这两个运行时中可能缺少一个函数或不同的实现
有关更多信息,请参阅本文:很高兴为您提供帮助!另外,试着时不时地关闭远程调试,看看是否有什么东西突然中断。我肯定会这么做的!谢谢,萨吉夫,我也有同样的问题。你找到解决办法了吗?我也有同样的问题。