TypeError: func.apply is not a function 类型错误:func.apply 不是一个函数

15 浏览
0 Comments

TypeError: func.apply is not a function 类型错误:func.apply 不是一个函数

我正在尝试使用useEffect函数,像这样:

const [data, setData] = useState({ courses: [] });
useEffect(async () => {
    const result = await axios.get(
        "http://example.com/api/v1/categories/"
    );
    await setData(result.data);
}, []);
console.log(data);
return (
    {data.info1}
    {data.info2}
    {data.info3}
    {data.info4}
);

但是当我尝试使用`data`变量时,有时会抛出以下错误:

TypeError: func.apply is not a function
HTMLUnknownElement.callCallback
C:/asdasd/node_modules/react-dom/cjs/react-dom.development.js:188
  185 |     window.event = windowEvent;
  186 |   }
  187 | 
> 188 |   func.apply(context, funcArgs);
      | ^  189 |   didError = false;
  190 | } // Create a global error event handler. We use this to capture the value
  191 | // that was thrown. It's possible that this error handler will fire more

我不知道我错在哪里。

0