Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to remove listner in the right way in react native navigation with class components

$
0
0

when I use removeListner function to remove the listner on navigation, I got a warning about that and that the remove not works correctly.

  componentDidMount() {    this.props.navigation.addListener('focus', this.props.didFocus);    this.props.navigation.addListener('blur', this.props.didBlur);  }  componentWillUnmount() {    this.props.navigation.removeListener('focus',this.props.didFocus);    this.props.navigation.removeListener('blur',this.props.didBlur);    }  }

in old versions of Navigation it was used like the following example :

 subscribe : NavigationEventSubscription; componentDidMount() {   this.subscribe = this.props.navigation.addListener('didFocus', this.props.didFocus);  }  componentWillUnmount() {    if(this.subscribe){     this.subscribe.remove();}    }  }

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>