Whats the difference between type babel and jsx

前端 未结 1 1961
傲寒
傲寒 2021-02-05 16:17

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.. pleas

1条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 16:33

    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.

    0 讨论(0)
提交回复
热议问题