React Js Basics
React Js Basics
JSX
Nested JSX elements
In order for the code to compile, a JSX expression must
have exactly one outermost element. In the below const myClasses = (
block of code the <a> tag is the outermost element. <a href="https://www.codecademy.com">
<h1>
Sign Up!
</h1>
</a>
);
ReactDOM.render(<h1>Render me!</h1>,
block shows some example JavaScript code that will
document.getElementById('app'));
need to be compiled.
<li>item 1</li>
begins. We see the closing parentheses on the line
<li>item 2</li>
following the end of the JSX expression.
<li>item 3</li>
</ul>
);
JSX attributes
The syntax of JSX attributes closely resembles that of
HTML attributes. In the block of code, inside of the const example = <h1 id="example">JSX
opening tag of the <h1> JSX element, we see an id Attributes</h1>;
attribute with the value "example" .
JSX className
In JSX, you can’t use the word class ! You have to use
className instead. This is because JSX gets translated // When rendered, this JSX expression...
into JavaScript, and class is a reserved word in const heading = <h1 className="large-
JavaScript. heading">Codecademy</h1>;
When JSX is rendered, JSX className attributes are
<h1 class="large-heading">Codecademy</h1>
<ul>{listItems}</ul>