Can JSX run without Babel?

Viewed 477

I just learned to set up a React project from scratch. I just wonder why can JSX run without a transpiler (Babel)? Because before I though I should use Babel to running JSX in a browser. Here is my setup so far:

  1. React 17.0.2
  2. ReactDOM 17.0.2
  3. Parcel

App.js

import React, { useState } from "react";
import ReactDOM from "react-dom";

const App = () => {
   const [name, setName] = useState("");

   function changeNameHandler(e) {
      setName(e.target.value);
   }

   return (
      <div>
         <input type="text" value={name} onChange={changeNameHandler} />
         <h1>Your name is {name}</h1>
      </div>
   );
 };

ReactDOM.render(React.createElement(App), document.getElementById("app"));
1 Answers

React doesn't require babel but the library is built on the concept of using ES6 javascript syntax.

React app however can be built with old ES5 syntax and JSX which would remove the need for Babel but you would lose the potential benefits of ES6.

So to make sure our React webapp is backwards compatible with version of JavaScript in current and older browsers or environments we use Babel.

Related