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

Putting it all together

Let's see how the whole component's structure would look like when putting all the methods together:

/*** ShoppingList.js ***/

import React from 'react';
import { Alert } from 'react-native';
import { ... } from 'native-base';

export default class ShoppingList extends React.Component {
static navigationOptions = {
title: 'My Groceries List'
};

constructor(props) {
...
}

/*** User Actions Handlers ***/
_handleProductPress(product) {
...
}

_handleAddProductPress() {
...
}

_handleClearPress() {
...
}

/*** Render ***/
render() {
...
}
}

The structure of a React Native component is very similar to a normal React component. We need to import React itself and then some components to build up our screen. We also have several event handlers (which we have prefixed with an underscore as a mere convention) and finally a render method to display our components using standard JSX.

The only difference with a React web app is the fact that we are using React Native UI components instead of DOM components. 

主站蜘蛛池模板: 呼图壁县| 哈巴河县| 屯昌县| 巴塘县| 惠安县| 遵义县| 措美县| 新泰市| 靖江市| 万山特区| 侯马市| 台南市| 庆安县| 株洲县| 保靖县| 陆河县| 台山市| 荆州市| 虹口区| 武鸣县| 苏尼特左旗| 甘肃省| 天长市| 额济纳旗| 嵊州市| 犍为县| 福海县| 巴楚县| 锡林郭勒盟| 兴业县| 南宁市| 赞皇县| 娄烦县| 定襄县| 友谊县| 蒲江县| 瑞安市| 南平市| 汉源县| 疏附县| 邢台市|