Introducing JSX
Consider this variable declaration:
const element = <h1>Hello, world!</h1>;
The above syntax is neither a string nor HTML.
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”. We will explore rendering them to the DOM.
It’s just translating those HTML tags into React.createElementcalls.
Embedding Expressions in JSX
In the example below, we declare a variable called name and then use it inside JSX by wrapping it in curly braces:
You can put any valid JavaScript expression inside the curly braces in JSX.
In the example below, we embed the result of calling a JavaScript function, formatName(user), into an <h1> element.