- 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.
- Linux設備驅動開發詳解:基于最新的Linux4.0內核
- pcDuino開發實戰
- Mastering ElasticSearch
- Windows Server 2012 Hyper-V:Deploying the Hyper-V Enterprise Server Virtualization Platform
- Kali Linux滲透測試全流程詳解
- Joomla! 3 Template Essentials
- Python UNIX和Linux系統管理指南
- Linux應用大全 基礎與管理
- bash shell腳本編程經典實例(第2版)
- Linux從入門到精通(視頻教學版)
- Linux內核修煉之道
- Windows網絡編程(第2版)
- 操作系統之哲學原理第2版
- Responsive Web Design with AngularJS
- 樹莓派+傳感器:創建智能交互項目的實用方法、工具及最佳實踐