Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected corresponding JSX closing tag for input Reactjs

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">             </div>         );     } }); 
like image 782
Sajin M Aboobakkar Avatar asked Jun 15 '15 18:06

Sajin M Aboobakkar


People also ask

How do I fix JSX element DIV has no corresponding closing tag?

If you have this error, try changing the Language Mode from "JavaScript" to "JavaScrip React" or "react". You can check that at the bottom right corner of VSC (see the picture below). To change it, click on it and type "react" and select the React language mode.

Is IMG a self closing tag in React?

That's why they don't need closing tags (also known as ENDTAGs). Everything they need is contained in their attributes, if that are any. Elements such a linebreak, <br> , horizontal rule, <hr> , <input> and <img> are self-closing, the latter two contain attrtibutes. React.

What is JSX element?

What is JSX? JSX stands for JavaScript XML. JSX allows us to write HTML in React. JSX makes it easier to write and add HTML in React.

Can we use JSX in React?

It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI should look like. JSX may remind you of a template language, but it comes with the full power of JavaScript. JSX produces React “elements”.


2 Answers

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.

like image 21
Yuvraj Patil Avatar answered Oct 05 '22 23:10

Yuvraj Patil


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

<input id="icon_prefix" type="text" class="validate" /> 
like image 137
Crob Avatar answered Oct 05 '22 23:10

Crob