[英]Visual Studio code parsing error, can't fix
"Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...?". “解析错误:相邻的 JSX 元素必须包含在一个封闭的标签中。你想要一个 JSX 片段 <>...?”。 That's the error that occurs which seems to be on the last bracket ");"
这就是发生的错误,似乎在最后一个括号“);” but I've tried everything yet my code will still not compile.
但我已经尝试了一切,但我的代码仍然无法编译。 I am new to this so the error might be obvious
我是新手,所以错误可能很明显
import React, { Component } from 'react'; import Header from '../Header/Header'; class MessageBoard extends Component { state = {} render() { return ( <div> <h1>Message Board</h1> <h2>Got any questions? Ask away!</h2> </div> <div class = "chat-popup" id="myform"> <form action="/action_page.php" class="form-container"> <h1>Chat</h1> <label for="msg"> <b>Message</b></label> <textarea placeholder="Type message.." name="msg" required> </textarea> <button type= "submit" class = "btn">Send</button> <button type="button" class="btn cancel" onclick="closeform()">Close</button> </form> </div> ); }
Enclose all returned html inside an element.将所有返回的 html 包含在一个元素中。 For example a
<div></div>
:例如
<div></div>
:
import React, { Component } from 'react';
import Header from '../Header/Header';
class MessageBoard extends Component {
state = {}
render() {
return (
<div>
<div>
<h1>Message Board</h1>
<h2>Got any questions? Ask away!</h2>
</div>
<div class = "chat-popup"
id="myform">
<form action="/action_page.php"
class="form-container">
<h1>Chat</h1>
<label for="msg">
<b>Message</b></label>
<textarea placeholder="Type
message.." name="msg" required>
</textarea>
<button type= "submit"
class = "btn">Send</button>
<button type="button"
class="btn cancel"
onclick="closeform()">Close</button>
</form>
</div>
</div>
);
}
} //<--- this bracket is missing in your example
Also, you are mising the last }
but I think this is a typo while copy pasting.另外,您错过了最后一个
}
但我认为这是复制粘贴时的错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.