Simple use of notification broadcast in react native.

Broadcast registration: addListener broadcasts the name notification_logout followed by the listener callback event

componentDidMount(): void {
    this.logoutListener = DeviceEventEmitter.addListener('notification_logout',() => {
        console.log("notification_logout")
        Actions.replace('login',{type:0})
    });
}

Monitor removal:

componentWillUnmount(): void {
    this.logoutListener.remove()
}

Broadcast call:

DeviceEventEmitter.emit('notification_logout', null);

Guess you like

Origin blog.csdn.net/qq_36355271/article/details/105521049