Reactjs action creator React/Redux的响应非常慢
我得到了超慢的响应时间(10秒以上)的功能,以调用我的行动创造Reactjs action creator React/Redux的响应非常慢,reactjs,redux,redux-thunk,Reactjs,Redux,Redux Thunk,我得到了超慢的响应时间(10秒以上)的功能,以调用我的行动创造 export function acceptContract(id) { return function(dispatch) { const config = { headers: { authorization: localStorage.getItem('etherToken') } }; const data = { data: id }; axios.put('/pending-contrac
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
有关。您只是直接调用函数,而没有分派它。就我所能说的而言,我所能做的就是返回一个永远不会被调用的函数,不知道如何得到响应。将呼叫更改为:
then( response => {
console.log(response);
dispatch(getPendingContracts());
})
是的,这正是我所期望的。这给了我一个延迟的回复,真奇怪。