1、发送页面A
import { View, DeviceEventEmitter } from 'react-native'
export default function A({ props}) {
//发送通知
const sendMsg = () => {
console.log("发送通知 send")
let send = {
name:"test",
age:18
}
DeviceEventEmitter.emit("sendmsg",send)
}
...
}
2、接收、监听页面B
import React, { useEffect} from 'react'
import { View, DeviceEventEmitter } from 'react-native'
export default function B({ props}) {
let sub = null
useEffect(() => {
console.log("加载监听")
sub = DeviceEventEmitter.addListener("sendmsg",res=>{
console.log("接收到send = "+JSON.stringify(res))
})
return () => {
console.log("移除send")
sub.remove()
}
}, [])
...
}