I ran forEach inside the render block and it outputs normally on the console, but the text tag is not displayed on the output.
What is the problem?
import React from "react";
import { StyleSheet, Text, View } from "react-native";
class Lotto extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 6,
maxNum: 45
};
this.lottoSet = this.createLottoNumber();
}
createLottoNumber() {
let lottoSet = new Set();
let rNum;
for (let i = 0; i < this.state.count; i++) {
rNum = Math.round(Math.random() * (this.state.maxNum * 1) + 1);
if (lottoSet.has(rNum)) i--;
else lottoSet.add(rNum);
}
return lottoSet;
}
render() {
return (
<View style={styles.container}>
{this.lottoSet.forEach(n => {
console.log(`<Text style={styles.item}>${n.toString()}</Text>`);
return <Text style={styles.item}>{n.toString()}</Text>;
})}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#333",
flexDirection: "row",
paddingTop: "10%",
justifyContent: "center"
},
item: {
color: "#fff",
textAlign: "center",
width: "100px"
}
});
export default Lotto;