Looking for an advice or best practices on this. Am I doing it right?
My Reducer:
export default function(){
return [
{
id: '01',
name: 'Cersei Lannister',
city: 'Kings Landings'
},
{
id: '02',
name: 'Margaery Tyrell',
city: 'Hign Garden'
},
{
id: '03',
name: 'Daenerys Targaryen',
city: 'Dragon Stone'
},
{
id: '04',
name: 'Ygritte',
city: 'Free Folk'
},
{
id: '05',
name: 'Arya Stark',
city: 'Winter Fell'
}
]
}
I've combined this reducer in allReducers as gotPeople. I am using this in a component myApp:
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import { connect } from 'react-redux';
class MyApp extends Component {
render(){
const renData = this.props.gotPeople.map((data, idx) => {
return (
<View key={idx}>
<Text>{data.id}</Text>
<Text>{data.name} of {data.city}</Text>
</View>
)
});
return(
<View>
{renData}
</View>
);
}
}
function mapStateToProps (state) {
return {
gotPeople: state.gotPeople
}
}
export default connect( mapStateToProps )( MyApp )
And when I import MyApp from ./MyApp; in my index.android.js and call it in the View like <MyApp /> it works. Everything is displayed properly. I'm not sure if this is a proper way to do it? Is there any better way?
Please advice.