没有子级的JSX元素必须是自动关闭的 [英] JSX elements with no children must be self-closing

查看:80
本文介绍了没有子级的JSX元素必须是自动关闭的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以正确运行此代码.但是,当我将代码提交到git时,它显示为错误:src/layouts/index.tsx:25:9-没有子级的JSX元素必须是自动关闭的".

I can run this code correctly. But when I commit my code to git, it shows 'ERROR: src/layouts/index.tsx:25:9 - JSX elements with no children must be self-closing'.

我试图添加React.Fragment标签.但这是行不通的.我也删除了第25行.但是显示了相同的错误.仍然是"index.tsx:25:9". 我也曾尝试使用自我封闭.但是我必须将值放入Menu.Item.

I have tried to add React.Fragment tag. But it doesn't work. I also delete line 25. But the same error shows. Still 'index.tsx:25:9'. I also have tried to use to be self-closing. But I have to put value into the Menu.Item.

这是我的代码:

import * as React from 'React';
import {Menu, Icon} from 'antd';
import './test.less';
import styles from './index.css';

const SubMenu = Menu.SubMenu;
class LeftBar extends React.Component{
  constructor(props: any) {
    super(props);
  }
  hideLeftBar = () => {
    // console.log(styles);
  }
  public render() {
    return (
      <div className={styles.leftbar}>
        <Menu
          className={styles.menu}
          mode="inline"
          // openKeys={this.state.openKeys}
          // onOpenChange={this.onOpenChange}
          style={{ width: 250 }}
        >
          <SubMenu className="test" key="sub1" title={<span><Icon type="mail" /><span>Navigation One</span></span>}>
            <Menu.Item key="2">Option 2</Menu.Item>
            <Menu.Item key="3">Option 3</Menu.Item>
            <Menu.Item key="4">Option 4</Menu.Item>
          </SubMenu>
          <SubMenu key="sub2" title={<span><Icon type="appstore" /><span>Navigation Two</span></span>}>
            <Menu.Item key="5">Option 5</Menu.Item>
            <Menu.Item key="6">Option 6</Menu.Item>
            <SubMenu key="sub3" title="Submenu">
              <Menu.Item key="7">Option 7</Menu.Item>
              <Menu.Item key="8">Option 8</Menu.Item>
            </SubMenu>
          </SubMenu>
          <SubMenu key="sub4" title={<span><Icon type="setting" /><span>Navigation Three</span></span>}>
            <Menu.Item key="9">Option 9</Menu.Item>
            <Menu.Item key="10">Option 10</Menu.Item>
            <Menu.Item key="11">Option 11</Menu.Item>
            <Menu.Item key="12">Option 12</Menu.Item>
          </SubMenu>
          <div onClick={this.hideLeftBar} className={styles.hide}/>
        </Menu>
      </div>
    );
  }
}

export default LeftBar;

希望我可以成功提交并将其推送到我的远程存储库中.

Hoping that I can commit successfully and push it to my remote repository.

推荐答案

此错误仅表示而不是例如:

This error just means instead of e.g.:

<div></div>

您应该拥有:

<div />

后者是自动关闭的.

这篇关于没有子级的JSX元素必须是自动关闭的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆