How JSX works in ReactJS? 🤗

researchjrs

Jyoti Ranjan Sharma

Posted on January 1, 2023

How JSX works in ReactJS? 🤗

React uses JSX to make developer experience better than other environments. JSX is just an HTML like syntax, but not HTML in Javascript. The Browser can't understand JSX code on it's own. It needs transpilers like Babel to convert JSX code to React.createElement() code, React.createElement() are nothing but JavaScript Objects and then those objects are converted to DOM.

So the flow goes like:
JSX => Babel => React.createElement => Obj => HTML code(DOM)


"Babel is a Beast."


Before compiling React JSX code, we need Babel to transpile it to the React API format.

JSX Element

const reactElement = <h1>Hello World</h1>
Enter fullscreen mode Exit fullscreen mode

Babel transpiled react version

const reactElement = /*#__PURE__*/React.createElement("h1", null, "Hello World");
Enter fullscreen mode Exit fullscreen mode

Reactlogo


Conclusion

  • JSX is HTML-like syntax, but not actual HTML in JS file.
  • Babel is a Beast.

YouTube Link
jyotisemail@gmail.com

💖 💪 🙅 🚩
researchjrs
Jyoti Ranjan Sharma

Posted on January 1, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related