【问题标题】:How are you supposed to flowtype redux thunk?你应该如何流式输入redux thunk?
【发布时间】:2017-06-07 03:55:44
【问题描述】:

我目前正在做的是:

export type Action =
   { type: 'FOO' }
 | { type: 'BAR' }

export type Thunk = (dispatch: Dispatch, getState: GetState) => Action | Thunk 

export type Dispatch = ReduxDispatch<Action> & (action: Thunk) => void

但如果您直接在 store 上发送,则如果不重新创建 store 将无法正常工作:

export type Store = ReduxStore&lt;State, Action&gt;

总的来说,我的 thunk 解决方案似乎还有其他小问题。有人有redux-thunk 的工作库定义吗?我在任何地方都找不到。

【问题讨论】:

    标签: reactjs redux react-redux redux-thunk


    【解决方案1】:

    到目前为止,我发现的最好的例子是 Facebook 自己的 F8 应用程序 here 中使用的例子。

    和你的很相似:

    export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
    export type GetState = () => Object;
    export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
    export type PromiseAction = Promise<Action>;
    

    到目前为止,它在我的项目中对我来说效果很好,尽管我不会直接在任何地方的商店中发货。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 2021-09-23
      • 2019-03-23
      • 2016-06-12
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多