- Hands-On Design Patterns with React Native
- Mateusz Grzesiukiewicz
- 199字
- 2021-08-13 15:12:58
Introduction to JSX
We have been using JSX so far, but what does it mean? JSX stands for JavaScript extension. How can it be an extension?
As you probably know, ECMAScript is also an extension to JavaScript (kind of). ECMAScript transpiles to JavaScript. What does this mean? It means that it just transforms ECMAScript code into valid JavaScript code. JavaScript misses out on many features that we like from ECMAScript, such as arrow functions, classes, and destructuring operators.
JSX works the same way. JSX is being transpiled to JavaScript, and its main feature is creating React elements based on the markup you write.
Could we use only JavaScript? Yes. Is it worth it? Most likely not.
Let's check this out in action. This is JSX and ECMAScript:
export default () => <Text style={{marginTop: 30}}>Example Text!</Text>
Now, compare this to pure JavaScript:
export default function() {
return React.createElement(
Text,
{style: {marginTop: 30}},
'Example Text!'
);
}
There's no doubt that the first code snippet is easier to read and understand.
- 自己動手寫搜索引擎
- Java 開發(fā)從入門到精通(第2版)
- Mastering Ubuntu Server
- 21天學(xué)通C++(第6版)
- 自制編程語言
- The DevOps 2.5 Toolkit
- 從零開始學(xué)C語言
- Selenium Testing Tools Cookbook(Second Edition)
- 移動互聯(lián)網(wǎng)軟件開發(fā)實驗指導(dǎo)
- Vue.js 2 Web Development Projects
- 讓Python遇上Office:從編程入門到自動化辦公實踐
- 精通Rust(第2版)
- Visual C++實用教程
- Learning Akka
- 正則指引(第2版)