Skip to content

Commit 2973c86

Browse files
committed
🚀 [Example] Add a button to change the list data
1 parent 6478cfa commit 2973c86

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

example/src/App.js

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import React, { Component } from 'react';
2-
import { Text, View } from 'react-native';
2+
import { Text, View, Button } from 'react-native';
33

44
// eslint-disable-next-line import/no-unresolved, import/extensions
55
import ImmutableListView from 'react-native-immutable-list-view/src/ImmutableListView';
66

77
import style from './styles';
8-
import listData from './listData';
8+
import mockData from './listData';
99

1010
class App extends Component {
1111

12+
state = {
13+
listData: mockData,
14+
};
15+
16+
changeData() {
17+
this.setState({
18+
listData: mockData.setIn(['Section A', 1], 'This value was changed!'),
19+
});
20+
}
21+
1222
renderRow(rowData) {
1323
return <Text style={style.row}>{JSON.stringify(rowData)}</Text>;
1424
}
@@ -23,8 +33,14 @@ class App extends Component {
2333
<Text style={style.welcome}>
2434
Welcome to React Native!
2535
</Text>
36+
<View style={style.button}>
37+
<Button
38+
onPress={() => this.changeData()}
39+
title="Update Data"
40+
/>
41+
</View>
2642
<ImmutableListView
27-
immutableData={listData}
43+
immutableData={this.state.listData}
2844
renderRow={this.renderRow}
2945
renderSectionHeader={this.renderSectionHeader}
3046
/>

example/src/styles.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ const style = StyleSheet.create({
1010
welcome: {
1111
fontSize: 20,
1212
textAlign: 'center',
13-
margin: 10,
13+
margin: 20,
14+
},
15+
button: {
16+
padding: 20,
17+
paddingTop: 0,
1418
},
1519
row: {
1620
fontSize: 13,

0 commit comments

Comments
 (0)