cantaş
cantaş

Reputation: 136

TypeError: This'VARIABLE_NAME' is not a function

I wanna define to null. Why won't it let me do this? I'm getting a TypeError error. I think there was no such problem with older versions?I want to treat this variable like 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();
}

Upvotes: 0

Views: 51

Answers (1)

Adam Jenkins
Adam Jenkins

Reputation: 55613

componentWillMount gets called before componentDidMount - this is a typo. You meant to write unsubscribe in componentWillUnmount, not componentWillMount

Upvotes: 1

Related Questions