简体   繁体   English

React Uncaught TypeError:传播不可迭代实例的无效尝试

[英]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.

相关问题 未处理的拒绝(TypeError):散布不可迭代实例的无效尝试 - Unhandled Rejection (TypeError): Invalid attempt to spread non-iterable instance 类型错误:传播不可迭代实例和合成事件的尝试无效 - TypeError: Invalid attempt to spread non-iterable instance and Synthetic Events TypeError:传播不可迭代实例的无效尝试 - TypeError: Invalid attempt to spread non-iterable instance Redux Web扩展 - 未捕获的TypeError:无效尝试传播不可迭代的实例 - Redux Web Extension - Uncaught TypeError: Invalid attempt to spread non-iterable instance 在Flatlist React Native中传播不可迭代实例的无效尝试 - Invalid attempt to spread non-iterable instance in Flatlist React Native 传播不可迭代实例的尝试无效 - Invalid attempt to spread non-iterable instance 未捕获的 TypeError:无效的解构不可迭代实例的尝试 - Uncaught TypeError: Invalid attempt to destructure non-iterable instance React + Redux:未处理的拒绝(TypeError):散布不可迭代实例的无效尝试 - React + Redux: Unhandled Rejection (TypeError): Invalid attempt to spread non-iterable instance Usestate + Setstate [TypeError: Invalid attempt to spread non-iterable instance.] - React Native Form Handling - Usestate + Setstate [TypeError: Invalid attempt to spread non-iterable instance.] - React Native Form Handling TypeError:对不可迭代实例 React/Jest 的解构尝试无效 - TypeError: Invalid attempt to destructure non-iterable instance React/Jest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM