<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
Check the element in Chrome Developer Tools and you should see the following:
Now let's cut out the whole div class from the HTML file and put it in our js file so it looks like this:
Take a look at your browser and inspect it. You should see something like this:
🏆CODING TIME COMPLETED
Did you notice that it changed div classname to div class? Grammar in JSX is mostly the same as HTML with some slight differences.
In HTML, we use class as an attribute name:
<h1 class="big">Hello</h1>
In JSX, we use className instead:
<h1 className="big">Hello</h1>
This is because JSX is translated into JS and class is a reserved word in JS. When JSX is rendered, JSX className attributes are rendered as class attributes.
Example of a code which uses className:
import React from 'react';
import ReactDOM from 'react-dom';
const myDiv = (
<div className="big">
I AM A BIG DIV
</div>
);
ReactDOM.render(myDiv, document.getElementById('app'))