在 react 中怎么配合 ts 发请求呢?
一般react 发thunk 请求的步骤流程是这样的:
为了方便理解我还画了一张图,就是有一丢丢的抽象…
下面是具体的代码
首先在组件中通过 dispatch 来触发 异步的 actions 代码
dispatch (xxxaction())
然后就走到了 action 的具体模块里面
一般会先在 store/index.ts 文件里面定义数据类型
// 这里定义的是获取 reducer 里面的全部的数据
type RootState = ReturnType<typeof store.getState>
// 这里定义的是同步的
// 假如这是 xx 模块
export type xxxAction =
{
type: 'xxx/GET_LIST'. payload:string} |
{
type: 'xxx/CHANGE_LIST'. payload:string}
//这里是 yy 模块
export type yyyAction =
{