共计 355 个字符,预计需要花费 1 分钟才能阅读完成。
const RenderItem = (item) => {const { children} = item;
const [showChild, setShowChild] = useState(false);
return (
<>
<div>Item!!!</div>
{showChild && children.length > 0 && (
<>
// 应用一般函数会报错
{children.map((ele) => (<>{RenderItem(ele)}</>
))}
</>
)}
</>
);
};
下面的代码会报错:Rendered more hooks than during the previous render.
将调用本身那行改成这种就好了:
{children.map(ele => <RenderItem item={ele} />}
依照标准,RenderItem,R 要大写
正文完
发表至: javascript
2022-05-11