相关文章推荐
想出国的豌豆  ·  jqgrid单元格编辑-掘金·  1 年前    · 
打酱油的油条  ·  json传递数组-掘金·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

While creating a component in Reactjs with input fields error occurs Error: Parse Error: Line 47: Expected corresponding JSX closing tag for input at http://localhost/chat-react/src/script.js:47:20 </div>

var Main = React.createClass({
    render: function() {
        return (
            <div className="card-action">
                <i class="mdi-action-account-circle prefix"></i>
                <input id="icon_prefix" type="text" class="validate">
                @pedro If a tag is empty (no children elements) this is a shorthand way to close the element without having to create a matching closing element. So instead of: <div></div> . you can just do <div />.  See here for more: reactjs.org/docs/…
– Jose Browne
                Jul 18, 2019 at 14:14
                I had a <br> and this was causing the problem (it expected a <br /> instead). This is weird because HTML5 specs advises to don't use the leading slash for self closing tags
– Christian Vincenzo Traina
                Jul 6, 2020 at 11:24
                @CristianTraìna It's important to remember that JSX is not HTML.  JSX is it's own thing. Behind the scenes everything is converted to React.createElement and it depends on the closing of each element to know how things are intended to be nested.
– Crob
                Jul 8, 2020 at 15:01

It happens when we do not close a html tag.

Make sure all the html tags are closed.

In my case it was the <br> tag. It should be <br />.

Try temporarily removing piece of code until you find which html tag closing is missing.

This error also happens if you have got the order of your components wrong.

Example: this wrong:

 <ComponentA> 
    <ComponentB> 
    </ComponentA> 
 </ComponentB> 

correct way:

  <ComponentA> 
    <ComponentB>
    </ComponentB>  
  </ComponentA> 

All tags must have enclosing tags. In my case, the hr and input elements weren't closed properly.

Parent Error was: JSX element 'div' has no corresponding closing tag, due to code below:

<hr class="my-4">
<input
  type="password"
  id="inputPassword"
  class="form-control"
  placeholder="Password"
  required
<hr class="my-4"/>
<input
 type="password"
 id="inputPassword"
 class="form-control"
 placeholder="Password"
 required

The parent elements will show errors due to child element errors. Therefore, start investigating from most inner elements up to the parent ones.

You need to close the input element with /> at the end. In React, we have to close every element. Your code should be:

<input id="whatever-id" type="text" class="validate" />
                Please provide an explanation of how and why this solves the problem would really help to improve the quality of your post
– Android
                Jun 21, 2019 at 12:18
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.