Чтобы я не делал, вылетает ошибка "TypeError: _client2.default.map is not a function".
Все никак не пойму как с Json вытаскивать данные.
Пожалуйста, напишите пример как из Json получить данные?
import React, {Component} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {select2} from '../actions/index';
import data from '../reducers/client2.json';
class ClientsList extends Component {
showList(){
{data.map( function (item, index) {
return (<li key={index}>{item.general.firstName} </li> );} )
}
return this.props.clients.map ((client) =>{
return(
<li onClick={() => this.props.select (client)}
key={client.general.firstName}>{client.general.firstName} </li>
);
});
}
render (){
return (
<ol>
{this.showList()}
</ol>
);
}
}
function mapStateToProps (state){
return {
clients: state.clients
};
}
function matchDispatchToProps (dispatch){
return bindActionCreators({select2: select2}, dispatch)
}
export default connect(mapStateToProps, matchDispatchToProps)(ClientsList);
[
{
"general": {
"firstName": "Liana",
"lastName": "Crooks",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
},
"job": {
"company": "Ledner, Johnson and Predovic",
"title": "Investor Functionality Coordinator"
},
"contact": {
"email": "Gerry_Hackett77@gmail.com",
"phone": "(895) 984-0132"
},
"address": {
"street": "1520 Zemlak Cove",
"city": "New Devon",
"zipCode": "42586-7898",
"country": "Guinea-Bissau"
}
},
{
"general": {
"firstName": "Liana",
"lastName": "Crooks",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/kevinoh/128.jpg"
},
"job": {
"company": "Ledner, Johnson and Predovic",
"title": "Investor Functionality Coordinator"
},
"contact": {
"email": "Gerry_Hackett77@gmail.com",
"phone": "(895) 984-0132"
},
"address": {
"street": "1520 Zemlak Cove",
"city": "New Devon",
"zipCode": "42586-7898",
"country": "Guinea-Bissau"
}
}
]