简体   繁体   English

ReactJs:地图函数中的道具类型无效。 `array` 类型的无效道具 `children`

[英]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.

相关问题 类型为“boolean”的prop`function`无效 - Invalid prop `function` of type `boolean` React Native错误失败的道具类型:提供给`Overlay`的`array`类型的无效道具`children`, - React Native error Failed prop type: Invalid prop `children` of type `array` supplied to `Overlay`, 警告:失败的道具类型:提供给`Dropzone`的类型`string`的prop`child`无效,期望的`function` - Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `Dropzone`, expected `function` 道具类型失败:提供给“CSSTransition”的道具“children”无效 - Failed prop type: Invalid prop `children` supplied to `CSSTransition` 提供给“对话框”的“功能”类型的无效道具“打开” - Invalid prop `open` of type `function` supplied to `Dialog` React-(嵌套)道具类型无效; 它必须是一个函数 - React - (nested) prop type is invalid; it must be a function 无效的道具:道具的类型检查失败 - Invalid prop: type check failed for prop 警告:道具类型失败:提供给“提供者”的对象类型为“对象”的道具儿童无效,需要一个ReactElement - Warning: Failed prop type: Invalid prop `children` of type `object` supplied to `Provider`, expected a single ReactElement reactjs 失败的道具类型:提供给“ForwardRef(IconButton)”的“object”类型的无效道具“className”,应为“string” - reactjs Failed prop type: Invalid prop `className` of type `object` supplied to `ForwardRef(IconButton)`, expected `string` 提供给叠加层的“数组”类型的道具“子项”无效。 期望单个反应元素 - Invalid prop 'children' of type 'array' supplied to overlay. Expected a single react element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM