Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between type babel and jsx

Tags:

html

reactjs

I just started using React JS ... I'm sorry but I am confused on what is the difference between type="text/babel" and type="text/jsx"

and when do I use them.. please help me understand.

like image 200
treb Avatar asked Mar 29 '16 03:03

treb


People also ask

Is Babel needed for JSX?

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.

Is TypeScript and JSX same?

TypeScript is a language that is a syntactic-superset of JavaScript. JSX is FaceBook's XML-like syntax extension to JavaScript, not a language per se.

What is the difference between JSX and ES6?

JSX: JavaScript XML Utilizing JSX allows us to write HTML elements in JavaScript, which is then rendered to the DOM. ES6 (aka: ECMAScript 6, JavaScript 6, or ECMAScript 2015) is the “6th version” of JavaScript, released in 2015.

What is JSX Babel and Webpack in React?

JSX is an extension to JavaScript which allows us to write XML-like syntax to define DOM elements, which are translated by Babel into vanilla JS. Webpack is responsible for bundling all of our components together and running a local development server to test our code in the browser.


1 Answers

Babel is a transpiler that turns input code into "pure" JavaScript.

JSX is a syntax sugar over JavaScript. You write .jsx and transpile it to .js using a transpiler (typically, Babel).

When you write text/babel you are saying to the Babel library that you want to transpile that script into pure JavaScript.

In case you write text/jsx you are saying your script is in .jsx and you need a transpiler to parse your code.

If you want to write .jsx and/or ES6 without configuring a bundler like webpack or browserify, load Babel through a CDN and use text/babel for simplicity.

like image 113
Rafael Quintanilha Avatar answered Oct 02 '22 16:10

Rafael Quintanilha