[英]getting undefined is not iterable (cannot read property Symbol(Symbol.iterator))
Learning React by coding, here i got this error (Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) ), dont know where is the problem, any suggestion?通过编码学习 React,在这里我得到了这个错误(Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))),不知道问题出在哪里,有什么建议吗?
simply useEffect activates setFilteredData which gives: `只需 useEffect 激活 setFilteredData 即可:`
{
links: [
{
color: 'red'
},
],
nodes: [
{
focused: focused
},
],
};
`
i want to take that data and change it a little, like my logic is, color should be grey or red if id's matches and also focus should be focus if id's matches, english is not my mother language so could be mistakes.我想获取该数据并对其进行一些更改,就像我的逻辑一样,如果 id 匹配,颜色应该是灰色或红色,如果 id 匹配,则焦点应该是焦点,英语不是我的母语,所以可能是错误的。 any ideas?
有任何想法吗? i hope my question is clear, if needs to add something or not clear, just tell me.
我希望我的问题很清楚,如果需要添加或不清楚,请告诉我。
const [filteredData, setFilteredData] = useState(); const LINK_COLOR = "grey"; const LINK_FOCUS_COLOR = "red"; useEffect(() => { const filterData = () => { setFilteredData({ links: links, nodes: allNodes }); }; filterData(); }, [...]); const focusLinkId = currentLink? currentLink.id: ""; const focusNodeId = currentNode? currentNode.id: ""; const graphData = {...filteredData, links: [...filteredData?.links, { color: filteredData?.links?.map((l) => { const color = l?.id === focusLinkId? LINK_FOCUS_COLOR: LINK_COLOR; return color; }), }, ], nodes: [...filteredData?.nodes, { focused: filteredData?.nodes?.map((n) => { const focused = n?.id === focusNodeId; return focused; }), }, ], }; console.log("graphData:", graphData); <Graph id="graph-id" data={graphData? graphData: visualGraph.model} />
As said in the comments, filteredData
is undefined
until the response comes back正如评论中所说,
filteredData
在响应返回之前是undefined
的
This should help:这应该有助于:
const graphData = filteredData && { /* ... */ }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.