reactjs - Redux actions callback
问题描述
I am stuck in a situation wherein I call a redux action which updates state in store which in turn updates one component. I want to receive a callback when that component is updated. How can I receive that callback ?
解决方案
如果需要接收回调,则需要使用 callbackable-actions 标准化动作。
actions-creator
包具有回调能力,您可以使用它来创建具有回调能力的动作对象。
npm install actions-creator
import actionsCreator from "actions-creator"
const my_callback = () => {
console.log("Hello, I am callback!!!")
}
const callbackable_action = actionsCreator.CALLBACKABLE.EXAMPLE(1, 2, 3, my_callback)
console.log(callbackable_action)
// {
// type: "CALLBACKABLE/EXAMPLE",
// args: [1, 2, 3],
// cb: f() my_callback,
// _index: 1
// }
callbackable_action.cb()
// "Hello, I am callback!!!"
有关详细信息,请参阅:Actions Creator
推荐阅读
- php - 如何使用 php 从 dhtmlx 调度程序保存/更新事件
- magento - Magento 2 在扩展模板中使用自定义块
- c++ - c++ 内联友元函数会导致名称隐藏在命名空间之间吗?
- amazon-web-services - S3 存储桶对象访问拒绝现有的
- json - 在 react native 中访问数据 JSON
- reactjs - CKEditor 如何在取消帖子时删除服务器中的图像文件
- blockchain - 如何使用 JSON RPC 检查门罗币钱包中是否有金额?
- r - Highchart 堆积柱
- sql - 如何将完整查询作为参数传递
- asynchronous - 如何在 Flutter 中获取当前位置时显示加载微调器?