JSX, which stands for Javascript XML, is a JavaScript syntax extension for React that allows you to write your components in a format similar to HTML. By transforming Html elements into React elements, JSX enables us to write HTML elements in Javascript and add them to the DOM without the use of additional methods like createElement()
or appendChild()
. Javascript and HTML work well together to create apps that are more powerful and perform better.
JSX appears to be HTML, however there are several differences. For instance, when you use class=""
in HTML in JSX you will need to use className=""
to add an HTML class to an element.
Other differences may apply. For instance, you might have come across odd markup like <></>
, which is known as a fragment (<></>
is a shortcut for <React.Fragment></React.Fragment>
). This is used to encapsulate elements that don't have a parent div.
You may also find custom elements in JSX such as <Dropdown />
. You can create these unique elements to group and reuse some codes throughout your project. Custom components always have a capital letter at the beginning.
You may achieve it manually modifying attributes like class=""
( to className=""
) , for=""
(to htmlFor=""
) that differ between JSX and HTML. It could become difficult as the HTML you're translating gets bigger, especially for svgs. The simplest option is to convert using our free website.