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

  • React Native Blueprints
  • Emilio Rodriguez Martinez
  • 200字
  • 2021-07-02 15:20:03

Building the FeedsList screen

The list of feeds will be used as the home screen for this app, so let's focus on building the list of the feeds' titles:

/** * src/screens/FeedsList.js ***/

import React from 'react';
import { Container, Content, List, ListItem, Text } from 'native-base';

export default class FeedsList extends React.Component {
render() {
const { feeds } = this.props.screenProps.store;
return (
<Container>
<Content>
<List>
{feeds &&
feeds.map((f, i) => (
<ListItem key={i}>
<Text>{f.title}</Text>
</ListItem>
))
</List>
</Content>
</Container>
);
}
}

This component expects to receive the list of feeds from this.props.screenProps.store and then iterates over that list building a NativeBase <List>, showing the titles for each of the feeds on the store. 

Let's introduce some MobX magic now. As we want our component to be re-rendered when the list of feeds changes (when a feed is added or removed), we have to mark our component with the @observer decorator. MobX will automatically force the component re-rendering on any update. Let's see now how to add the decorator to our component:

...

@observer
export default class FeedsList extends React.Component {

...

That's it. Now, our component will be notified when the store is changed and a re-render will be triggered.

主站蜘蛛池模板: 和龙市| 南康市| 通州区| 松溪县| 雷波县| 苏尼特右旗| 石河子市| 盐边县| 临江市| 威海市| 府谷县| 正定县| 茌平县| 万山特区| 上高县| 偃师市| 文登市| 江源县| 清水河县| 松溪县| 扎鲁特旗| 阳城县| 吉林省| 平罗县| 商丘市| 辽阳市| 平阴县| 虎林市| 汤阴县| 论坛| 喜德县| 龙南县| 洛南县| 聊城市| 顺平县| 南皮县| 泰和县| 漾濞| 阿图什市| 沾化县| 临夏市|