动作创建者的响应非常慢 React/Redux
Very slow response from action creator React/Redux
我的动作创建器中要调用的函数的响应时间非常慢(超过 10 秒)。
export function acceptContract(id) {
return function(dispatch) {
const config = { headers: { authorization: localStorage.getItem('etherToken') } };
const data = { data: id };
axios.put('/pending-contracts/accept',
data,
config
).then( response => {
console.log(response);
getPendingContracts();
})
.catch( response => {
// If the get doesn't work, boot the user out to index.
console.log(response);
});
}
}
我更新了我的数据库中的合同值之一,然后我希望 redux 为用户分派新列表以在 UI.
上显示更新
不确定为什么 getPendingContract() 调用需要这么长时间。我几乎立即从后端收到响应。
export function getPendingContracts() {
return function(dispatch) {
axios.get('/pending-contracts', {
headers: { authorization: localStorage.getItem('etherToken') }
})
.then( response => {
console.log('in getPendingContracts')
return dispatch({
type: PENDING_CONTRACTS_LIST,
payload: response.data.message
});
})
.catch( response => {
// If the get doesn't work, boot the user out to index.
console.log(response);
});
}
}
此问题可能与您从 acceptContract
呼叫 getPendingContracts
的方式有关。您只是直接调用该函数,而不是分派它。据我所知,所有会做的就是 return 你一个永远不会被调用的函数,完全不确定你是如何得到响应的。将调用更改为:
then( response => {
console.log(response);
dispatch(getPendingContracts());
})
我的动作创建器中要调用的函数的响应时间非常慢(超过 10 秒)。
export function acceptContract(id) {
return function(dispatch) {
const config = { headers: { authorization: localStorage.getItem('etherToken') } };
const data = { data: id };
axios.put('/pending-contracts/accept',
data,
config
).then( response => {
console.log(response);
getPendingContracts();
})
.catch( response => {
// If the get doesn't work, boot the user out to index.
console.log(response);
});
}
}
我更新了我的数据库中的合同值之一,然后我希望 redux 为用户分派新列表以在 UI.
上显示更新不确定为什么 getPendingContract() 调用需要这么长时间。我几乎立即从后端收到响应。
export function getPendingContracts() {
return function(dispatch) {
axios.get('/pending-contracts', {
headers: { authorization: localStorage.getItem('etherToken') }
})
.then( response => {
console.log('in getPendingContracts')
return dispatch({
type: PENDING_CONTRACTS_LIST,
payload: response.data.message
});
})
.catch( response => {
// If the get doesn't work, boot the user out to index.
console.log(response);
});
}
}
此问题可能与您从 acceptContract
呼叫 getPendingContracts
的方式有关。您只是直接调用该函数,而不是分派它。据我所知,所有会做的就是 return 你一个永远不会被调用的函数,完全不确定你是如何得到响应的。将调用更改为:
then( response => {
console.log(response);
dispatch(getPendingContracts());
})