我用 React 建立了一个迷你网站 - 一切都工作正常,直到我今天登录。现在我无法渲染它,而是收到以下错误:“AbortController”未定义”。
部分代码是:
const useFetch = (url) => {
const [data, setData] = useState(null);
const [isPending, setIsPending] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const abordCont = new AbortController();
setTimeout(() => {
fetch(url, { signal: abordCont.signal })
.then(res => {
if(!res.ok) {
throw Error('could not fetch data for that recource');
}
return res.json();
})
.then(data => {
setIsPending(false);
setData(data);
setError(null);
})
.catch(err => {
if (err.name === 'AbortError') {
console.log('fetch aboarded');
} else { …Run Code Online (Sandbox Code Playgroud)