Section two shows the page title

Source: Internet
Author: User


# code
when the project was just created, only one JS file, index.android.js, we simplify it, the code is as follows:

import React, {
Appregistry,
Component,
Text} from ' react-native ';

class Note extends component{
render () {
Return (
<Text>
Write notes
</Text>
);
};
};
appregistry.registercomponent (' Note ', () = note);

# React Native Program execution process
1. Index.android.js is the entry file, starting from here.
2. Since react is modular, we will first create a root component, which is the note
3. We need to register the root component
4. After the program starts, the root component is displayed first, where the "write notes" is simply displayed at the top left of the screen.

# ES2015 's modular system
import React, {
Appregistry,
Component,
Text} from ' react-native ';
this part of the role is to import some features of the react-native package, here react is the default import, only one, the other curly braces, may be
classes, functions, and variables, so long as we use them, we'll import them beforehand.
when we want to invoke the functions provided by other modules in the JS file, we must import them first.

# Component Concepts for react
class Note extends component{

This is to create a component that inherits from component, implementing the Render function.
We have created this component and will be able to use it in JSX in the future in <Note> </Note>, and using the react native encapsulated
<Text> components are no different, which is why react is a component.
A simple description of the REACT concept: the first core concept of react is the virtual DOM, regardless of which platform the virtual DOM abstracts the interface hierarchy,
the properties and state of each component. When the state changes, react compares the difference to the previous state, and then simply render the part that needs to be modified, without all
painting. React is a web technology that has separated react-dom, which is a component of HTML tags, Render, and in turn, React Native
it only encapsulates the Android and iOS-related components, so react's core architecture, after implementing a set of components of Render, will work on the mobile platform.
Similarly, if we are using the window API to implement the render of the component on the Win32 platform, this technique can also be used for desktop development and is native, use
js for Windows apps. A third party has now implemented render on the Mac.


# JSX
This component only implements the Render function and works as expected, and the function is to render itself
What the function body returns is the JSX syntax, the simplest form of this syntax:
<Text>
Write notes
</Text>

Why is it a simplified notation? Because react's original writing is like this.
render () {
Return (
react.createelement (' Text ', null, ' Write notes ')
)}
createelement The last parameter, you might also be ready to nest calls to createelement, which is a very disorganized code.
so Facebook offers the Jsx language

method, before it is run, converts it into a form such as createelement.

# register the root component:

React native provides a appregistry for registering the first rendered component, called the root component.


Note, is a class where the notation actually creates an instance of the note class, invoking the method of constructing the note class

# Separate Note components:
Generic items, there will not be only one source file.
We created the SRC directory, created a note.js file in it, and then ported the components here. Add the necessary references for the component class
Add default export: Export defaults.
In Index.android.js, delete the code and import of the component, and add the import to '. \src\note '.

Section two shows the page title

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.