admin管理员组文章数量:1326669
I'm having trouble creating a simple ponent that renders a menu in my react application.
This is the code for my ponent:
import React, { Component } from 'react';
export default class menu extends Component {
render() {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<a className="navbar-brand" href="#">Navbar</a>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavDropdown">
<ul className="navbar-nav">
<li className="nav-item active">
<a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Features</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Pricing</a>
</li>
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a className="dropdown-item" href="#">Action</a>
<a className="dropdown-item" href="#">Another action</a>
<a className="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
);
}
}
I'm putting it in the other ponent.
import menu from './ponentes/menu';
constructor(props) { super(props) this.state = { sistemas: [] }; }
class App extends Component {
render() {
return (
<div>
<menu></menu>
</div>
<div className="App">
<div className="bs-header" id="content">
<div className="container">
<h1>Template Changelog</h1>
<p>Lists all changes to the HTML template files</p>
</div>
</div>
); //[js] JSX expressions must have one parent element.
}
}
I'm also getting the following error in the mented line
[js] JSX expressions must have one parent element.
I'm having trouble creating a simple ponent that renders a menu in my react application.
This is the code for my ponent:
import React, { Component } from 'react';
export default class menu extends Component {
render() {
return (
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<a className="navbar-brand" href="#">Navbar</a>
<button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNavDropdown">
<ul className="navbar-nav">
<li className="nav-item active">
<a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Features</a>
</li>
<li className="nav-item">
<a className="nav-link" href="#">Pricing</a>
</li>
<li className="nav-item dropdown">
<a className="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div className="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a className="dropdown-item" href="#">Action</a>
<a className="dropdown-item" href="#">Another action</a>
<a className="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
);
}
}
I'm putting it in the other ponent.
import menu from './ponentes/menu';
constructor(props) { super(props) this.state = { sistemas: [] }; }
class App extends Component {
render() {
return (
<div>
<menu></menu>
</div>
<div className="App">
<div className="bs-header" id="content">
<div className="container">
<h1>Template Changelog</h1>
<p>Lists all changes to the HTML template files</p>
</div>
</div>
); //[js] JSX expressions must have one parent element.
}
}
I'm also getting the following error in the mented line
[js] JSX expressions must have one parent element.
Share Improve this question asked Apr 10, 2018 at 0:34 Rafael AugustoRafael Augusto 7975 gold badges15 silver badges28 bronze badges 1-
fyi you should capitalize
menu
. – Daniel A. White Commented Apr 10, 2018 at 0:46
2 Answers
Reset to default 5Your App
has more than one top level div
. Wrap both in another div
.
In React 16, you can wrap your ponents with Fragment
which is a cleaner approach as pared to wrap it with additional div
tag.
All you have to do is just import Fragment
from react library.
import React, { Component, Fragment } from 'react';
And you can use it
<Fragment>
<ComponentA />
<ComponentB />
</Fragment>
Documentation: https://reactjs/docs/fragments.html
Otherwise you can just wrap your ponents with div
tag as mentioned by @Daniel A. White
本文标签: javascriptmust be wrapped in an enclosing tagStack Overflow
版权声明:本文标题:javascript - must be wrapped in an enclosing tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742202426a2432210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论