简体   繁体   English

Visual Studio 代码解析错误,无法修复

[英]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> ); }

JSX expressions must have one parent element JSX 表达式必须有一个父元素

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.

相关问题 有人可以修复我的代码以复制按钮吗? (Visual Studio 代码) - Can someone fix my code for a button to copy? (Visual Studio Code) 如何在 Visual Studio 代码上修复智能感知? - How can i fix intelliSense on visual studio code? Visual Studio Code和ESLint不会检测到拼写错误,例如“ style.backgroundCOlor”。 我怎样才能解决这个问题? - Visual Studio Code and ESLint aren't detecting typos e.g. “style.backgroundCOlor”. How can I fix this? 如何修复 Visual Studio 代码中未找到模块? - how to fix MODULE NOT FOUND in visual studio code? Visual Studio Code Debugger 看不到数组数据 - Visual Studio Code Debugger can't see arrays data 我在 Visual Studio Code-JavaScript 中看不到 output - I can't see the output in Visual Studio Code-JavaScript 无法使用 Visual Studio Code 终端运行节点文件 - Can't run node file using Visual Studio Code terminal 无法使用 Debugger for Chrome 在 Visual Studio Code 中放置断点 - Can't place breakpoints in Visual Studio Code with Debugger for Chrome 无法使用 Visual Studio Code 调试 Azure JavaScript Function - Can't Debug Azure JavaScript Function using Visual Studio Code 父母 function 没有正确关闭后,Visual Studio 代码没有给出错误如何修复? - Visual studio code doesnt give out error after parents function didnt close corectly how to fix?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM