React Redux 动态模块加载模块与承诺状态

React Redux dynamic module loading module with promise instated of state

技术栈

我试图在 Redux-Dynamic-Module 库的帮助下动态加载减速器,在示例代码中我确实实现了动态加载。但是在使用连接函数时获得承诺而不是状态对象。

const mapStateToProps = (store: any) => {
    return { products: store.productOptions }    <-- here I'm getting store.productOption as Promise
};


const ProductOptionsWrapper: any = connect<any, any, any, any>(
  mapStateToProps,
  {}
)(ProductOptionComponent);

是否尝试 await 解决 Promise

const mapStateToProps = async (store: any) => {
  let data = store.productOptions;
  data = await data.then((r: any) => r);
  return { product: data };
};

但是低于错误并且没有进入状态。

mapStateToProps() in Connect(ProductOptionComponent) must return a plain object. Instead received [object Promise].

而且我无法更新存储,因为存储中的数据存储为 Promise。

所以我需要帮助如何正确使用 redux-dynamic-module 和 redux-connect。

Note:- Also using reux-thunk middleware

经过大量搜索后,这是一个打字错误。

我使用 async reducer function 进行 async 调用(只是 redux-thunk 的另一种方式的 POC)。

export async function rootReducer(){ ... }

删除 async 后它按预期工作。