RN DeviceEventEmitter传值

类似于iOS的发送通知 NSNoticationCenter

引入:

import {
     DeviceEventEmitter
 } form 'react-native';

接收:

componentDidMount() {
     this.subscription = DeviceEventEmitter.addListener('userNameDidChange',(userName) =>{
          alert('通知');
     })
}

移除:

componentWillUnmount() {
    // 移除
    this.subscription.remove();
}

发送:

DeviceEventEmitter.emit('userNameDidChange', '通知来了');