【发布时间】:2018-06-15 19:03:53
【问题描述】:
我需要使用实时搜索 axios 请求取消上一个请求 - 我正在使用油门去抖动来发出请求,但是当现有单词被删除并更新新值时我遇到了问题 - 结果显示为前一个单词在某些情况下,我认为我需要取消所有先前对同一 requestID 的请求,通读文章,但它们都不适合我的用例。任何帮助都是我的代码。
减速器:
switch (action.type) {
case GETTING_DATA:
return {
...state,
results: action.payload,
};
case SEARCH_DATA:
return {
...state,
Results: action.payload,
};
export function getSearch(value) {
return (dispatch) => {
dispatch({
type: GETTING_DATA,
});
const arg = {
search: value,
};
apiGet('abc', arg).then(response =>
getResults(dispatch, response));
};
}
const getResults = (dispatch, response) => {
dispatch({
type: SEARCH_DATA,
payload: response.data,
});
};
服务:
export const apiGet = async (path = '', args = {}) => {
const endpoint = "/aaa/aaa/aaa";
try {
return axios.get(endpoint, getConfig());
} catch (e) {
}
};
【问题讨论】:
标签: react-redux axios debounce