Javascript TypeError:这个';变量名称';这不是一个函数
我想定义为空。为什么它不让我这么做?我收到一个打字错误。我认为旧版本没有这样的问题?我想把这个变量当作typescriptJavascript TypeError:这个';变量名称';这不是一个函数,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我想定义为空。为什么它不让我这么做?我收到一个打字错误。我认为旧版本没有这样的问题?我想把这个变量当作typescript unsubscribe: null ; componentDidMount() { const user = this.props.uid || Fire.shared.uid; this.unsubscribe = Fire.shared.firestore .collection("users")
unsubscribe: null ;
componentDidMount() {
const user = this.props.uid || Fire.shared.uid;
this.unsubscribe = Fire.shared.firestore
.collection("users")
.doc(user)
.onSnapshot(doc => {
this.setState({ user: doc.data() });
})
}
componentWillUnMount() { // EDITED
this.unsubscribe();
}
componentWillMount
在componentDidMount
之前调用-这是一个输入错误。您的意思是在componentWillUnmount
中写入unsubscribe,而不是componentWillMount
是的,谢谢。但我仍然在这一行中得到一个错误(unsubscribe:null;)。情况没有改变。如果我们不能再做这样的演示,我还能写什么呢?@cantaşunsubscribe=null