Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I really need Babel or other transpilers to use ES6 with React?

Do I really need Babel or other transpilers to use ES6 in React?

I was looking at the chart https://kangax.github.io/compat-table/es6/

Seems like my current browser Chrome (latest stable version) supports almost all the ES6 features...

If I can use ES6 without Babel, how I should do it?

like image 559
user3463521 Avatar asked Jun 25 '16 17:06

user3463521


People also ask

Is Babel necessary for React?

If you work on a React project, chances are you have to deal with Babel. It is needed for 2 main tasks: To compile JSX into React.

Do you really need Babel?

Using modern language features and browser APIs makes writing code easier, faster, and more fun. It also makes your code more maintainable. If you're happy writing ES5 and using XMLHttpRequest() , you definitely don't need Babel, but you might need some kind of therapy.

Does React need a transpiler?

Whenever we write React Code, we always build/transpile it to JavaScript that browsers can understand. This is generally done with tools like Babel or TypeScript. If you use tools and libraries like Create React App, they will do the transpilation for you behind the scenes.

Does ES6 need to be Transpiled?

js and it supports ES6 features, you don't need to transpile your code. Your code only works in the same place, if it is hosted in one place. Transpiler is used, when your code is written in newer versions, there may be users which use browsers with old versions of Javascript.


1 Answers

If you want to:

  • use modules (with require() or import ...)
  • use JSX
  • support a lot of browsers
  • use more advanced features (async/await), some still in proposals (decorators, class properties..)

You must use Babel to be sure that everyone will be able to run your code, else you can develop without it.

like image 105
Kerumen Avatar answered Oct 11 '22 20:10

Kerumen