Expected corresponding JSX closing tag for input Reactjs

前端 未结 6 1026
醉话见心
醉话见心 2020-12-23 15:50

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/

相关标签:
6条回答
  • 2020-12-23 16:22

    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.

    0 讨论(0)
  • 2020-12-23 16:35

    You have to close all tags like , etc for this to not show.

    0 讨论(0)
  • 2020-12-23 16:35

    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="icon_prefix" type="text" class="validate/">
    
    0 讨论(0)
  • 2020-12-23 16:39

    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> 
    
    0 讨论(0)
  • 2020-12-23 16:46

    You need to close the input element with a /> at the end.

    <input id="icon_prefix" type="text" class="validate" />
    
    0 讨论(0)
  • 2020-12-23 16:46

    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
     >
    

    Fix:

    <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.

    0 讨论(0)
提交回复
热议问题