<React Native mobile development practices>-1-React Native's JSX solution-1-reactjsx
JSX is not a new development language, but a syntax proposed by Facebook: A syntactic sugar that allows you to directly write HTML tags in JavaScript code. Therefore, JSX is essentially a JavaScript language.
TIPS: syntaxes (Syntactic sugar) is by British computing scientist Peter randing (https://zh.wikipedia.org/wiki/% E5 % BD % BC % E5 % BE % 97% C2 % B7 % E5 % 85% B0 % E4 % B8 % 81) A term invented is a syntax added to a computer language. This syntax does not affect the functions of the language, but is more convenient for programmers. Syntactic sugar makes the program more concise and more readable.
In React and React Native development, you do not have to use JSX. You can also directly use JavaScript for development. However, we strongly recommend that you use JSX! JSX is simple and clear when defining a tree structure similar to HTML, which greatly improves the efficiency of development and maintenance.
The following uses the code in section 1.4's first React Native application as an example:
01 export default class ch02 extends Component {// each page can be understood as a Component 02 render () {// function 03 return (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 ); 17} 16}
In the above Code, the component's render () method function is used to render the page, and its return value is a View object. But why didn't I find the code for creating objects and setting properties? Originally, JSXTransformer helped us compile and convert the XML-Like syntax in the Code into real and available JavaScript code. It not only creates View objects, sets View styles and la S, but also is more considerate, the tree structure between views is also built. For example, the tree structure in the preceding example is as follows:
Root View (style container)---- Sub Text 1 (style welcome)---- Sub Text 2 (style instructions)---- Sub Text 3 (style instructions)
Learn With Me, React Native mobile development practices