I'm doing an android application with the expo framework. I'm a beginner with react native and I need some help to understand a strange behavior.
Why this code is compiling when the second not ? I just add one empty View node.
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return (
<Text style={styles.getStartedText}>
Questionary:
</Text>
);
}
and this code in not compiling :
render() {
if (this.state.isLoading) {
return (
<View style={{flex: 1, paddingTop: 20}}>
<ActivityIndicator />
</View>
);
}
return (
<Text style={styles.getStartedText}>
Questionary:
</Text>
<View></View> //because of this !!
);
}
In return
you can have only one node, so you need to wrap all your nodes ( Text
, View
) with a parent:
return (
<View>
<Text style={styles.getStartedText}>
Questionary:
</Text>
<View></View>
</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.