react-nativereact-native-router-flux

react-native-router-flux addListener doesn't work


I am using

react-native": "0.62.2", react-native-router-flux: "4.2.0-beta.1",

addListener doesn't work, and console.log never invoke

    componentDidMount() {
        this.props.navigation.addListener(ActionConst.RESET, () => {
            console.log('RESET');
        });
        this.props.navigation.addListener(ActionConst.FOCUS, () => {
            console.log('FOCUS');
        });
        this.props.navigation.addListener(ActionConst.PUSH, () => {
            console.log('PUSH');
        });
        this.props.navigation.addListener(ActionConst.POP_TO, () => {
            console.log('POP_TO');
        });
}

is there a way or documentation that I can look into?


Solution

  • You only have

    To add listener

    componentDidMount(){
        const didBlurSubscription = this.props.navigation.addListener(
          'didBlur',() => {
             console.log('didBlur');
           }
        );
    }
    
    componentWillUnmount(){
        // Remove the listener when you are done
        didBlurSubscription.remove();
    }
    

    DOC (v4.2.x is based on React Navigation v4.x)