javascript - 如何在 React 中使用单个调度来调度多个动作?
问题描述
我正在做一个项目,但仍在学习 React。所以目前,我的函数中有以下内容。有人告诉我,像这样的大量调度会导致问题,除了看起来很乱,并建议创建一个调度。我该怎么做呢?
dispatch({
type: 'UPDATE_ARRAY',
orderItemsArray: newitemsArray,
});
dispatch({
type: 'UPDATE_NUMBER',
tickNumber: tickNumber,
});
dispatch({
type: 'UPDATE_MESSAGE',
message: orderMessage,
})
解决方案
使用 redux-batched-actions。
const mapDispatchToProps = (dispatch) => ({
action2: id => dispatch(Actions.action2(id)),
action3: id => dispatch(Actions.action3(id)),
action1: (dateId, attrId) =>
dispatch(batchActions([
Actions.action2(dateId),
Actions.action3(attrId)
]))
});
当在没有任何性能优化的情况下开箱即用时,有两个主要问题: React 将重新渲染多次 React Redux 将多次重新评估选择器
推荐阅读
- github - 邀请某人在 github 中使用管理员权限进行协作
- c++ - 链表只在调试中删除,在构建中不删除
- javascript - 我们如何制作一个带有滚动条的 div 元素,使其垂直滚动条顶部位置为 100px?
- javascript - 限制multiple-file-input-field中上传的文件数量
- android - 使用 Android 模拟器反应本机应用程序崩溃而没有错误
- node.js - AWS Fargate:节点 js 内存泄漏
- flopy - Flopy 生成的 shapefile 不考虑 MODFLOW DIS lenuni 值?
- swift - AVAudioPlayer 使用命令中心暂停后继续“播放”
- python - 我想到处隐藏光标移动
- html - 如何在 CSS 中使用偏移量来实现双边框?