[英]ReactJs: Invalid prop type in map function. Invalid prop `children` of type `array`
Warning: Failed prop type: Invalid prop children
of type array
supplied to ForwardRef(ListItemIcon)
, expected a single ReactElement.警告:失败的道具类型:提供给
ForwardRef(ListItemIcon)
array
类型的道具children
项无效,应为单个 ReactElement。
in Link (at App.js:258)在链接中(在 App.js:258)
in ul (created by ForwardRef(List))在 ul(由 ForwardRef(List) 创建)
in ForwardRef(List) (created by WithStyles(ForwardRef(List)))在 ForwardRef(List) (由 WithStyles(ForwardRef(List)) 创建)
in WithStyles(ForwardRef(List)) (at App.js:255)在 WithStyles(ForwardRef(List))(在 App.js:255)
in div (at App.js:249)在 div 中(在 App.js:249)
const sideList = side => (
<div
className={classes.fullList}
role="presentation"
onClick={toggleDrawer(side, false)}
onKeyDown={toggleDrawer(side, false)}
>
<List>
{["Домашняя страница", "Войти", "Акции", "Служба поддержки"].map(
(text, index) => (
<Link
key={index}
to={`${(index === 0 && "/") ||
(index === 1 && "/LoginPage") ||
(index === 2 && "/Sales") ||
(index === 3 && "/Contacts")}`}
>
<ListItem button key={text}>
<ListItemIcon>
{index === 0 && <HomeIcon />}
{index === 1 && <AccountBoxIcon />}
{index === 2 && <MonetizationOnIcon />}
{index === 3 && <ContactSupportIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
</Link>
)
)}
</List>
<Divider />
<List>
{/* <ListItem>
<ListItemIcon button key={"Выйти"}>
<ExitToAppIcon />
</ListItemIcon>
<ListItemText primary="Выйти" />
</ListItem> */}
{["Выйти", `Город: ${city}`].map((text, index) => (
<Link key={index} to={`${index === 1 && "/UserCityPage"}`}>
<ListItem button key={text}>
<ListItemIcon>
{index === 0 && <ExitToAppIcon />}
{index === 1 && <LocationCityIcon />}
</ListItemIcon>
<ListItemText primary={text} />
</ListItem>
</Link>
))}
</List>
</div>
);
I had the same issue just because the <ListItem>
should be a direct child of <List>
.我遇到了同样的问题,因为
<ListItem>
应该是<List>
的直接子级。 Try to move the <Link>
to be child of <ListItem>
not vice versa.尝试将
<Link>
移动为<ListItem>
子项,反之亦然。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.