/
EmployeeList.js
50 lines (42 loc) · 1.29 KB
/
EmployeeList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, {Component} from 'react';
import _ from 'lodash';
import {View, Text, ListView} from 'react-native';
import { connect } from 'react-redux';
import {employeesFetch} from '../actions';
import ListItem from './ListItem';
class EmployeeList extends Component {
componentWillMount(){
this.props.employeesFetch();
//creating data source
this.createDataSource(this.props);
}
componentWillReceiveProps(nextProps){
this.createDataSource(nextProps);
}
createDataSource({ employees }){
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.dataSource = ds.cloneWithRows(employees);
}
renderRow(employee) {
return <ListItem employee={employee} />
}
render() {
console.log(this.props);
return (
<View>
<ListView
enableEmptySections
dataSource = {this.dataSource}
renderRow={this.renderRow}
/>
</View>
);
}
}
const mapStateToProps = (state) => {
const employees = _.map(state.employee,(val,uid) => {
return { ...val, uid };
});
return {employees};
};
export default connect(mapStateToProps, {employeesFetch})(EmployeeList);