react|react 报错解决 Rendered more hooks than during the previous render.

const RenderItem = (item) => { const { children } = item; const [showChild, setShowChild] = useState(false); return ( <> Item!!! {showChild && children.length > 0 && ( <> // 使用普通函数会报错 {children.map((ele) => ( <>{RenderItem(ele)} ))} )} ); };

上面的代码会报错:Rendered more hooks than during the previous render.
将调用自身那行改成这种就好了:
{children.map(ele => }

【react|react 报错解决 Rendered more hooks than during the previous render.】按照规范,RenderItem,R要大写

    推荐阅读