Here is the function I'm calling below:
const timerDisplay = () => {
for (var i = 0; i < numbers.length; i++) {
return (
<Text>{numbers[i]}</Text>
)
}
}
Calling:
<View style={styles.timerTop}>
<Text style={styles.textTopBot}>{timerDisplay}</Text>
</View>
So, when I refresh the project it gets me the 'Functions are not valid as a React child'. How can I solve this?
尝试使用这个关键字
{timerDisplay} --> {this.timerDisplay}
<View style={styles.timerTop}>
<View style={styles.textTopBot}>
{numbers.map((number) => <Text>{number}</Text>)}
</View>
</View>
Assuming you are using class component.
//the function
timerDisplay = () => {
for (var i = 0; i < numbers.length; i++) {
return (
<Text>{numbers[i]}</Text>
)
}
}
//call the function
<View style={styles.timerTop}>
<Text style={styles.textTopBot}>{this.timerDisplay}</Text>
</View>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.