[英]React Uncaught TypeError: Invalid attempt to spread non-iterable instance
I am trying to push a project to gh-pages, locally, everything works fine but when I upload it to gh I get this console error "Uncaught TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a Symbol.iterator method."我正在尝试将项目推送到本地 gh 页面,一切正常,但是当我将其上传到 gh 时,我收到此控制台错误“未捕获的 TypeError:传播不可迭代实例的无效尝试。为了可迭代,非数组对象必须有 Symbol.iterator 方法。”
const addToFavorites = (item) => {
setFavorites([...favorites, item]);
saveToLocalStorage([...favorites, item]);
};
this piece of code seems to be the problem but I cannot figure it out这段代码似乎是问题,但我无法弄清楚
The error is trying to say that your favorites array is not iterable and therefore it is not able to spread them into the array that you are creating in the arguments for setFavorites and saveToLocalStorage.该错误试图说明您的收藏夹数组不可迭代,因此它无法将它们传播到您在 arguments 中为 setFavorites 和 saveToLocalStorage 创建的数组中。 Unless I take a look at your favorites array, I can't give you anymore information
除非我看看你的收藏夹数组,否则我不能给你更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.