Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:这个';变量名称';这不是一个函数_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript TypeError:这个';变量名称';这不是一个函数

Javascript 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")

我想定义为空。为什么它不让我这么做?我收到一个打字错误。我认为旧版本没有这样的问题?我想把这个变量当作typescript

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