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

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.

主站蜘蛛池模板: 新闻| 普陀区| 临澧县| 双鸭山市| 分宜县| 郧西县| 洱源县| 贵南县| 揭阳市| 武乡县| 河西区| 永平县| 闻喜县| 石家庄市| 衡阳县| 务川| 乐亭县| 安化县| 浪卡子县| 芦溪县| 庄浪县| 界首市| 玉龙| 青冈县| 商南县| 永清县| 永嘉县| 曲阜市| 和硕县| 高雄市| 顺昌县| 五原县| 怀仁县| 宁城县| 淳化县| 会理县| 申扎县| 青岛市| 高邮市| 和平区| 涪陵区|