技术栈
我试图加载减速器动态的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中间件
在搜索了很多之后,这是一个打字错误。
我使用异步减速器函数
进行异步
调用(只是redux-thunk的另一种方式的POC)。
export async function rootReducer(){ ... }
删除async
后,它会按预期工作。