依赖于当前状态REDUX的Call api请求

问题描述 投票:0回答:1

我有以下情况-我在组件内部调度了一个在redux存储中设置字段的函数:

// at this moment, itemsCount is equal to null 
dispatch(updateCountOfItems(5)); // updates itemsCount in store
dispatch(fetchItems()); // calls saga that fetches items and its based on itemsCount

和内部sagas:

const itemsCount = yield select((state) => state.itemsCount); // I need itemsCount to be up-to-date (5)
yield call(api.apiCall, itemsCount); // will itemsCount equal to 5? or null?

问题:我可以确定,在sagas中,在sagas中调用api时,itemsCount是最新的吗?因此,它等于分派的5吗?我可以确定100%吗?

javascript reactjs react-redux redux-saga
1个回答
0
投票

[调度动作是同步的,所以是的,您可以确定在完成状态下的fetchItems()更新之前,将不会调度itemsCount

© www.soinside.com 2019 - 2024. All rights reserved.