如果 fetch Promise尚未解决,在一定秒数后,我想向用户显示超时错误。
我在此处看到了一些添加 setTimeout 的好例子:https : //github.com/github/fetch/issues/175
但是如何处理也使用 redux 的 fetch promise 超时?例如
export function getData() {
return (dispatch, getState) => {
fetch('blah.com/data')
.then(response => response.json())
.then(json => dispatch(getDataSuccess(json)))
.catch(
error => {
console.log(error)
}
)
dispatch({
type: DATA_FETCH_REQUEST
})
}
}
谢谢阅读!