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要大写
推荐阅读
- 使用idea引入注解@SpringBootApplication报错Cannot resolve symbol 'SpringBootApplication'
- appium运行报错
- 如何在|如何在 pyqt 中解决启用 DPI 缩放后 QIcon 模糊的问题
- 在安卓6.0(及以上)设备上无法获取无线网卡MAC地址的解决方案
- 现代|现代 CSS 解决方案(CSS 数学函数)
- React-native 关于 android真机 出现连不上服务器
- 解决(Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x2)
- appium 报错
- zabbix--邮件告警报错“Support for SMTP authentication was not compiled in”
- Android - "已安装了存在签名冲突的同名数据包",解决方法!