<react Native mobile development combat >-1-react native JSX solution

Source: Internet
Author: User

JSX is not a new development language, but a syntax scheme that Facebook proposes: a syntactic sugar that can write HTML tags directly in JavaScript code, so JSX is essentially a JavaScript language.

Tip: syntax sugar (syntactic sugar) is by the British computational scientist Peter Landing (https://zh.wikipedia.org/wiki/%E5%BD%BC%E5%BE%97%C2%B7%E5%85%B0%E4%B8% 81) The invention of a term, refers to a computer language added to a grammar, which has no effect on the function of the language, but more convenient for programmers to use. The syntactic sugar makes the program more concise and more readable.

In the development of react and react native, it is not necessary to use JSX or to develop directly using JavaScript. However, it is strongly recommended that readers use jsx! Because JSX is simple and straightforward when defining a tree structure like HTML, it greatly improves the efficiency of development and maintenance.

The following is an example of the code in the first react native application in section 1.4:

The  default class Ch02 extends Component {//each page can be interpreted as a component                                  . The function of render () {//Rendered page          (04
   <view style={styles.container}>    //page root View05                  <text style={styles.welcome}>06                      Welcome to React native!07                  </text>08                  <text style={styles.instructions}>09                      to get started, edit Index.ios.js10                  </text>11                  <text style={styles.instructions}>12 Press                      cmd+r to reload,{' \ N '}13                      cmd+d or shake for dev menu14                  </text>15              </view>16          );  

  

In the code above, the render () method function of the component is used to render the page, and its return value is a View object, but why is there no code to create the object and set the property? Originally, Jsxtransformer helped us to translate the code's Xml-like grammar compilation into the actual JavaScript code, which not only created the View object, set the view style and layout, but also, more intimate, built the tree structure between the view. For example, the tree structure in the example above is like this:

Root View (Style container)----Sub Text 1 (style welcome)----Sub Text 2 (style instructions)----Sub Text 3 (Style instr Uctions)

  

Learn with me, "React native mobile development Combat"

<react Native mobile development combat >-1-react native JSX solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.