3 Introduction to JSX
This chapter covers
- Understanding JSX and its benefits
- Using JSX to implement custom components faster and easier
- React and JSX gotchas
JSX is a syntax extension to JavaScript. It is one of the things that make React great, but also one of the more controversial elements of React when it was introduced back in the day.
This is an example of using JSX in JavaScript:
const link = <a href="//reactjs.org">React</a>;
JSX is the element there between the angle brackets: <a href="//reactjs.org">React</a>. It's not a string. It's not a template literal. It's not HTML. It's a JavaScript object, but created with the syntax extension called JSX. It makes creating React elements much faster and more compact, but also makes reading React elements much easier. And the latter is at least as important as the former.
JSX is made for developers only. It does not by itself do anything to make better nor faster web applications. It is converted to the exact same code as not using JSX would do.
JSX is not a requirement, but is universally accepted as the only way to write React components. You may find a few teams out there not using JSX, but they are by far the minority.