Skip to content

Commit eb72991

Browse files
JoelMarceybubblesunyum
authored andcommitted
ES6-ify ListView Basics
Summary: Fixes facebook#8184 Closes facebook#8370 Differential Revision: D3477196 Pulled By: caabernathy fbshipit-source-id: 929f84b3f8edaf03f918bb04fb9dbb48b4884b18
1 parent f49bcf6 commit eb72991

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

docs/Basics-Component-ListView.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,21 @@ This example creates a simple `ListView` of hardcoded data. It first initializes
2020
> A `rowHasChanged` function is required to use `ListView`. Here we just say a row has changed if the row we are on is not the same as the previous row.
2121
2222
```JavaScript
23-
import React from 'react';
23+
import React, { Component } from 'react';
2424
import { AppRegistry, ListView, Text, View } from 'react-native';
2525

26-
var AwesomeList = React.createClass({
26+
class ListViewBasics extends Component {
2727
// Initialize the hardcoded data
28-
getInitialState: function() {
29-
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
30-
return {
28+
constructor(props) {
29+
super(props);
30+
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
31+
this.state = {
3132
dataSource: ds.cloneWithRows([
32-
'John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie'
33-
])
33+
'John', 'Joel', 'James', 'Jimmy', 'Jackson', 'Jillian', 'Julie', 'Devin'
34+
])
3435
};
35-
},
36-
render: function() {
36+
}
37+
render() {
3738
return (
3839
<View style={{paddingTop: 22}}>
3940
<ListView
@@ -43,8 +44,8 @@ var AwesomeList = React.createClass({
4344
</View>
4445
);
4546
}
46-
});
47+
}
4748

4849
// App registration and rendering
49-
AppRegistry.registerComponent('AwesomeProject', () => AwesomeList);
50+
AppRegistry.registerComponent('AwesomeProject', () => ListViewBasics);
5051
```

0 commit comments

Comments
 (0)