reactjs - 如何将带参数的函数传递给 setTimeout() 中的调度函数
问题描述
我想在收到服务器的响应后延迟调度操作。我正在使用 Redux_thunk。这是我的代码不起作用。
export const fetchActionCreator = ({ types, url, fetchOptions, dataKey }) => dispatch => {
const actions = typesToActionCreators(types);
dispatch(clientRequest());
let mock_Response = [key="A",value="xyz"];
return axios.get(url, fetchOptions)
.then(response => response.data,
error => console.log('an error occoured ' + error))
.then(data => {
console.log('time Before ' + new Date());
setTimeout(() => { dispatch(actions.success(mock_Response, dataKey)) }, 4000);
console.log('time After ' + new Date());
});
};
function typeToActionCreator(type) {
return typeof type === 'function' ? type : (payload, dataKey) => ({ type, payload, dataKey });
}
function typesToActionCreators(types) {
const [request, success, failure] = types.map(typeToActionCreator);
return { request, success, failure };
}
你能告诉我我在哪里犯错了吗?
解决方案
推荐阅读
- vim - `if char =~# '\w'` 在 Vimscript 中是什么意思?
- python - 使用循环来绘制带有龟模块的图案
- javascript - Node.js 分析器 - 共享库中的所有内容?
- google-apps-script - 复制文件夹中的所有文件,包括子文件夹中的文件
- php - 使用 php regex 从字符串中识别版本
- node.js - 如何在 multer 中捕获错误
- javascript - 使用 Highcharts 可以实现发散图表?
- autocomplete - Google 自定义搜索 API 自动完成功能是否会增加查询限制?
- python - 如何强制 python 对象为 isinstance 的其他特定类型?
- windows - Divio Windows 应用程序在准备日志时挂起