我从redux商店得到一些配置
dispatch(aOrder.getThrottlingConfig(storeId))之后,我想将redux中的值设置为组件存储
const throttlingConfig: IOrderConfig = useSelector<RootState, IOrderConfig>(({ root }) => root.order.throttling)
setCapacity(throttlingConfig.throttling.context.capacity)但是当组件挂载限制未定义时,如果尝试使条件
if (throttlingConfig.throttling) {
setCapacity(throttlingConfig.throttling.context.capacity)
}它永远不会执行,我做错了什么?我只想从Redux商店的setState时,他们的字段我需要的是更新
发布于 2020-07-16 21:13:54
在这个代码块中,您将root.order.throttling赋值给throttlingConfig,然后当您访问它时,您将尝试访问throttlingConfig.throttling.context.capacity。
const throttlingConfig: IOrderConfig = useSelector<RootState, IOrderConfig>(({ root }) => root.order.throttling) setCapacity(throttlingConfig.throttling.context.capacity)实际上应该是root.order.throttling.throttling.context.capacity。
因此,假设您的数据按照我所期望的那样结构化,这应该是可行的:
if (throttlingConfig) {
setCapacity(throttlingConfig.context.capacity)
}https://stackoverflow.com/questions/62935227
复制相似问题