react-smart-post:跨组件通信

时间:2021-05-18 14:04:49
【文件属性】:
文件名称:react-smart-post:跨组件通信
文件大小:2KB
文件格式:ZIP
更新时间:2021-05-18 14:04:49
react JavaScript 功能定位 解耦跨组件通信 比react-event功能强大,代码更少 比context更好理解使用简单 如何安装 npm i react-smart-post API //可能会收到消息的组件 smartPost.push(component); //发送消息到目标组件,目标组件直接改变state smartPost.post(messageState,targetComponentName); //发送消息到目标组件,目标组件仅仅在smartPostOn中收到信息 smartPost.post(messageState,targetComponentName,true); //目标组件收信息 smartPostOn=(message)=>{ console.log(message) } 使用方式 第一种方式 : 直接把此函数拷贝到项目公共函数中
【文件预览】:
react-smart-post-master
----README.md(2KB)
----.gitignore(5B)
----index.js(1KB)
----package.json(371B)

网友评论