Skip to content

Commit 8777182

Browse files
committed
sorting
1 parent 220baaf commit 8777182

File tree

1 file changed

+7
-1
lines changed
  • mobile/ReactNativeTutorial/app/bundles/comments/components/Index/List

1 file changed

+7
-1
lines changed

mobile/ReactNativeTutorial/app/bundles/comments/components/Index/List/List.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import { ListView } from 'react-native';
44
import Item from './Item/Item';
5+
import _ from 'lodash/fp';
56

67
import styles from './ListStyle';
78

@@ -26,7 +27,12 @@ class List extends React.Component {
2627
}
2728

2829
componentWillReceiveProps(nextProps) {
29-
this.setState({ dataSource: this.state.dataSource.cloneWithRows(nextProps.comments) })
30+
const data = _.compose(
31+
_.reverse,
32+
_.sortBy(_.get('id')),
33+
_.values
34+
)(nextProps.comments);
35+
this.setState({ dataSource: this.state.dataSource.cloneWithRows(data) })
3036
}
3137

3238
render() {

0 commit comments

Comments
 (0)