Uncaught TypeError: Invalid attempt to spread non-iterable instance.
1、报错信息:
报错Uncaught TypeError: Invalid attempt to spread non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method. at _nonIterableSpread (OgPanel.js:20:39) at _toConsumableArray (OgPanel.js:18:131) at handleSearchUser (OgPanel.js:223:1) at onSearch (Search.js:72:1) at onPressEnter (Search.js:81:1) at handleKeyDown (Input.js:136:1) at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1) at invokeGuardedCallback (react-dom.development.js:4277:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4291:1)
在setTreeData 中报错
解决办法:
1、是因为我的搞错了,我以为[...topObj] 会转成数组。其实不行。
正确的应该是
setTreeData([...treeData])
所以报错的关键就是在于,setTreeData输入的应该是数组,但是输入的不是数组,就会包上面的错误了。