官术网_书友最值得收藏!

Transforming JSX into JavaScript

"Shawn, as I mentioned, the JSX is transformed to the native JavaScript syntax."

// Input (JSX):
var app = <App name="Mike" />;

"This will eventually get transformed to"

// Output (JS):
var app = React.createElement(App, {name:"Mike"});
Tip

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  • Log in or register to our website using your e-mail address and password.
  • Hover the mouse pointer on the SUPPORT tab at the top.
  • Click on Code Downloads & Errata.
  • Enter the name of the book in the Search box.
  • Select the book for which you're looking to download the code files.
  • Choose from the drop-down menu where you purchased this book from.
  • Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

"If you would like to see this live in action, try this example at https://babeljs.io/repl/. It's a live REPL that can transform a JSX code to the native JavaScript code."

"There is another editor available for converting HTML to JSX. You can check it out at http://facebook.github.io/react/html-jsx.html. This allows you to paste an arbitrary HTML code that gets converted to JSX with extraction of styles, classes, and other information and then create a component on top of it." said Mike.

"Pretty handy. However, this is just for ease of development, right? What happens when we deploy our code?" asked Shawn.

"JSX is not meant to be compiled at runtime. Though there is a JSX transformer that converts JSX to JavaScript in a browser. Using it to compile JSX at runtime in the browser would slow down our application. We will use tools such as Babel, which is a JavaScript transpiler to convert our JSX code to the native JavaScript code before deploying the application."

主站蜘蛛池模板: 鲁甸县| 阳原县| 从江县| 黔西| 佛教| 博乐市| 墨玉县| 额敏县| 噶尔县| 怀化市| 镇江市| 临汾市| 崇礼县| 嘉禾县| 湘潭市| 吉安县| 赤城县| 南宫市| 陆河县| 青浦区| 新巴尔虎左旗| 封开县| 张北县| 辉县市| 武强县| 清远市| 黑河市| 永登县| 敦化市| 米泉市| 阳城县| 长宁区| 体育| 东海县| 龙里县| 岳池县| 三原县| 花莲市| 延吉市| 西乌珠穆沁旗| 宜都市|