In JSX, you can include expressions within curly braces { }
, which can be React variables, properties, or any valid JavaScript expression; JSX evaluates and returns the result.
Evaluate the expression 5 + 5.
const |
To write HTML across multiple lines, enclose the HTML within parentheses.
Create a list containing three items.
const |
The HTML code must be enclosed in a single top-level element. For example, if you want to write two paragraphs, they must be placed inside a parent element like a div.
Enclose two paragraphs within a single DIV element.
const |
JSX will generate an error if the HTML is incorrect or lacks a parent element. |
Alternatively, you can use a “fragment”—an empty HTML tag <></>
—to wrap multiple lines without adding extra nodes to the DOM.
Enclose two paragraphs within a fragment.
const |
JSX adheres to XML rules, so HTML elements must be properly closed.
Close empty elements with a />
at the end.
const |
JSX will produce an error if the HTML elements are not properly closed. |