小编Mil*_*tzé的帖子

反应错误:“错误‘AbortController’未定义”

我用 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)

controller reactjs

6
推荐指数
1
解决办法
1109
查看次数

标签 统计

controller ×1

reactjs ×1