'Trying to reset data when return to the page

I am trying to reset data when return to the page

here is my piece of code

    componentDidMount(){
        
        this.checkIfAlreadyLoggedIn();
        
        this.willFocusSubscription = this.props.navigation.addListener(
            'willFocus',
            () => {
                this.setState({products:[],alreadyLoadedCount:0});
                this.checkIfAlreadyLoggedIn();
            }
          );
    }

    componentWillUnmount() {
        this.willFocusSubscription();
    }

the page is perfectly reload but the problem is when i back to the previous page the follwing error shows

 ERROR  TypeError: this.willFocusSubscription is not a function. (In 'this.willFocusSubscription()', 'this.willFocusSubscription' is an instance of Object)

i put the above code in the previous page also. but the error shows same.



Solution 1:[1]

can you change 'willFocus' to 'focus' as show in the image below and check enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rsb