Tried using map() to render an array of JSX elements (tableData inside this.state) in React Native but I'm getting an array with undefined elements instead on the console.
Here is my code:
const TVSHOWIMAGETITLES = [
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist, BreakingBad,
MoneyHeist];
class HashTablesScreenTwo extends React.Component {
constructor(props) {
super(props);
this.state = {
fiveShows: this.props.route.params.selectedShows,
tableHead: ['Week', 'TV Shows'],
tableWeeks: [1, 2, 3, 4, 5],
tableData: []
}
}
renderTableData(){
const jsxArray = this.state.tableWeeks.map((i)=>{this.renderTVShowImageTitle(i-1)})
console.log(jsxArray)
console.log(this.state.tableWeeks)
return{
tableData: jsxArray
}
}
renderTVShowImageTitle(i) {
let index = this.state.fiveShows[i];
return (
<TVShow
id={index}
imageSource={TVSHOWIMAGETITLES[index]}
onClick={() => 1}
/>
)
}
render() {
const state = this.state;
{ this.renderTableData() }
return (
<View>
<Text>
Because you're ambitious,
you have decided to binge watch the shows at a rate of one show per week.
Here's how your planned schedule looks based on the order you have selected the shows:
</Text>
<View style={styles.container}>
<Table borderStyle={{ borderWidth: 2, borderColor: '#c8e1ff' }}>
<Row data={state.tableHead} style={styles.head} textStyle={styles.text} />
<Col data={state.tableWeeks} />
<Col data={state.tableData} />
</Table>
</View>
);
}
}
Appreciate it if someone could point out what I'm doing wrong here. Thanks!