JSX
Using React.createElement()
is very verbose, so most of the time we use JSX, a syntax extension to JavaScript. React brings HTML and JS together into an unholy creation called JSX. JSX allows us to write code that looks like HTML inside of our JavaScript but is eventually compiled down to JavaScript objects.
JSX is not valid JavaScript - but it is transpiled/compiled into valid JavaScript.
JSX Rules & Conventions
JSX can only render one top level element but that element can contain numerous children.
All tags need to be closed. Self-closing tags like
<img>
need to be written as<img />
.Any JavaScript within JSX must be enclosed in curly braces
{}
.
References
Last updated
Was this helpful?