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> ); } });
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.
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? JSX stands for JavaScript XML. JSX allows us to write HTML in React. JSX makes it easier to write and add HTML 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”.
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.
You need to close the input element with a />
at the end.
<input id="icon_prefix" type="text" class="validate" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With