简体   繁体   English

未终止的JSX内容-反应

[英]Unterminated JSX contents - react

    <div>
      <button style={{width: "100%"}} className="pt-button pt-intent-primary" onClick="{() => { this.authWithFacebook() }}">Log In with Facebook</button>
      <hr style={{marginTop: "10px", marginBottom: "10px"}}>
      <form onSubmit={(event) => { this.authWithEmailPassword(event) }} ref={(form) => { this.loginForm = form }}>
        <div style={{marginBottom: "10px"}} className="pt-callout pt-icon-info-sign">
          <h5>Note</h5>
          If you dont have an account already, this will create you one!
        </div>
        <label className="pt-label">
          Email
          <input style={{width: "100%"}} className="pt-input" name="email" type="email" ref={(input) => {this.emailInput = input}} placeholder="Email"></input>
          Password
          <input style={{width: "100%"}} className="pt-input" name="password" type="password" ref={(input) => {this.passwordInput = input}} placeholder="Password"></input>
        </label>
         <input style={{width: "100%"}} type="submit" className="pt-button pt-intent-primary" value="Log In"></input>
        </form>
    </div>

Error message: 错误信息:

Syntax error: D:/xxxx/xxxx/xxxx/webWorker/webworker/src/components/Login.js: Unterminated JSX contents (39:14)

I do not know what is the problem, it seems to be OK but I cant run it. 我不知道这是什么问题,看来还可以,但是我无法运行它。 Thank you for helping. 感谢您的帮助。

It is mainly about closing the <hr> tag. 它主要与关闭<hr>标签有关。 Better would be also to self-close the <input> tags like so <input type="text" /> . 更好的办法是像<input type="text" />这样自关闭<input>标记。 As a bonus I separated the <label> tag to each of the input fields, that way whenever you click on the field label it is focusing the right input field. 作为奖励,我将<label>标记分隔到每个输入字段,这样,每当您单击字段标签时,它都会聚焦在正确的输入字段上。

Before moving on I would recommend to read those two jsx guides: introduction , advanced . 在继续之前,我建议阅读这两个jsx指南: 简介高级

Your code after modifications: 修改后的代码:

<div>
  <button style={{width: "100%"}} className="pt-button pt-intent-primary" onClick="{() => { this.authWithFacebook() }}">Log In with Facebook</button>
  <hr style={{marginTop: "10px", marginBottom: "10px"}} />
  <form onSubmit={(event) => { this.authWithEmailPassword(event) }} ref={(form) => { this.loginForm = form }}>
    <div style={{marginBottom: "10px"}} className="pt-callout pt-icon-info-sign">
      <h5>Note</h5>
      If you dont have an account already, this will create you one!
    </div>
    <label className="pt-label">
      Email
      <input style={{width: "100%"}} className="pt-input" name="email" type="email" ref={(input) => {this.emailInput = input}} placeholder="Email"/>
      </label>
    <label className="pt-label">
      Password
      <input style={{width: "100%"}} className="pt-input" name="password" type="password" ref={(input) => {this.passwordInput = input}} placeholder="Password"/>
    </label>
     <input style={{width: "100%"}} type="submit" className="pt-button pt-intent-primary" value="Log In"/>
    </form>
</div>

尝试关闭<hr />标签,您也可以关闭输入标签<input /> ,因为它们也没有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM