javaLuo / react-luo

React Automatically - 保持最新技术 react18 hooks router6 webpack5 babel7 antd4

Home Page:https://isluo.com/work/pwa/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

您好,我想再次请教个问题,麻烦了

wangjunwei910208 opened this issue · comments

export const editProblem=(obj)=>{
Fetchapi.newPost(
'url',obj
).then(
msg => {
console.log(msg);
dispatch(xxxAction);
}
).catch(() => {
message.error('网络错误,请重试');
});
}
这个我写的一个函数(写在了一个公共函数的js文件里),我想在异步时的then()函数里请求成功时发送action,如上,但提示dispatch未定义,请问我怎么把dispatch弄进来

commented

如果你要这样export出去的话。

`
// 在组件页面的顶部引入两个东西:
import { bindActionCreators } from 'redux';
import { editProblem} from '../../a_action/app-action';

// 页面的底部这样写
export default connect(
(state) => ({
}),
(dispatch) => ({
actions: bindActionCreators({ editProblem}, dispatch),
}),
)(TestPageContainer);
`

好的 谢谢!