提问者:小点点

React Redux动态模块加载模块,保证状态稳定


技术栈

  • 反应,反应DOM-16.11。0
  • Redux-4.0。4
  • 反应redux-7.1。1
  • redux动态模块-5.1。一,

我试图加载减速器动态的Redux-动态模块库的帮助下,并在示例代码中实现了动态加载。

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);

尝试等待解决Promise

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

但是低于错误,而不是状态。

Connect(ProductOptionComponent)中的MapStateTops()必须返回普通对象。相反,我们收到了[反对promise]。

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

因此,我需要帮助如何正确使用redux动态模块与redux连接。

注意:-也使用reux-thunk中间件


共1个答案

匿名用户

在搜索了很多之后,这是一个打字错误。

我使用异步减速器函数进行异步调用(只是redux-thunk的另一种方式的POC)。

export async function rootReducer(){ ... }

删除async后,它会按预期工作。