React Native events listen to DeviceEventEmitter

A page

import { DeviceEventEmitter } from 'react-native'; .componentDidMount() {
    // Received listener
    this.listener = DeviceEventEmitter.addListener('Listening event name'.(msg) = > {
        console.log(msg);  / / to monitor
        // do something})}componentWillUnmount() {
    // Remove the listener
    if (this.listener) {
      this.listener.remove(); }}...Copy the code

B page

import { DeviceEventEmitter } from 'react-native'; .postMsg() {
    // Send the listening value
    let msg = "haha"
    DeviceEventEmitter.emit('Listening event name', msg); }...Copy the code