有屏幕Home和New。 Home显示存储在db中的数据列表。对db的新写入。主屏幕应重新显示用户导航到新数据但不显示新数据。这是预期的行为,是否有一个简单的解决方案?
主屏幕:
class Home extends React.Component {
static navigationOptions = {
title: 'Home',
};
constructor(props) {
super(props);
realm = new Realm({schema: [Case]});
this.state = {
cases: realm.objects('Case'),
}
};
render() {
const listItems = this.state.cases.map((data, index) =>
<View style={Styles.listItem}>
<Text key={index}>
{data.name}
</Text>
</View>
);
return (
<View>
<ScrollView>
{ listItems }
</ScrollView>
</View>
);
}
路由配置:
const MainScreenNavigator = TabNavigator({
Home: { screen: Home },
New: { screen: NewCase },
});
const SimpleApp = StackNavigator({
Home: { screen: MainScreenNavigator },
});
AppRegistry.registerComponent('SimpleApp', () => SimpleApp);