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

  • React Native Blueprints
  • Emilio Rodriguez Martinez
  • 169字
  • 2021-07-02 15:19:59

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. 

主站蜘蛛池模板: 罗源县| 大同县| 万安县| 台前县| 奈曼旗| 丹巴县| 镇原县| 富裕县| 汝州市| 南郑县| 洞头县| 永城市| 宜良县| 贞丰县| 乐亭县| 镇江市| 拜泉县| 克山县| 沁水县| 金山区| 鄂托克前旗| 平遥县| 潍坊市| 莒南县| 乐安县| 伊春市| 拜泉县| 麻栗坡县| 盐亭县| 昌邑市| 磐安县| 淳化县| 三明市| 吉木萨尔县| 辽源市| 息烽县| 乌兰浩特市| 方城县| 西吉县| 南漳县| 呼和浩特市|