【发布时间】:2018-04-01 07:03:17
【问题描述】:
如果收到outfitDetail 道具,我将在标题标题处呈现用户的图像和用户名。
class OutfitDetail extends Component {
static navigationOptions = ({navigation, screenProps}) => ({
...
headerTitle: (
!!screenProps.outfitDetail ? (
<View style={styles.container}>
<TouchableOpacity onPress={() => this.props.navigation.navigate('Profile', {id: userId})}>
{this._renderAvatar(screenProps.outfitDetail.user.image)}
</TouchableOpacity>
<View style={styles.content}>
<View style={styles.contentHeader}>
<RkText rkType='header5'>{screenProps.outfitDetail.user.username}</RkText>
<RkText rkType='secondary4 hintColor'>
<TimeAgo time={screenProps.outfitDetail.publish}/>
</RkText>
</View>
<RkText rkType='primary3 mediumLine'>{screenProps.outfitDetail.content}</RkText>
</View>
</View>
): (<Text>Loading</Text>)
),
...
});
所以如果 screenProps.outfitDetail 不为 null(尚未获取),则渲染 Loading,否则渲染用户的照片和用户名。
为什么我收到Unexpected token, expected , error (React-navigation)?
错误发生在上面的第三行代码。
【问题讨论】:
-
将
Loading 之前的 ',' 替换为 ':' 并可能像这样用(<Text>Loading</Text>)括起来 -
感谢您的评论。但它仍然在第三行抛出错误
-
你是对的!我也错过了
-
最后一行也缺少
},所以结尾是})}, -
刚刚编辑了问题的最后一行。我没有把整个代码放在这里。嗯,我认为我在第三行出现错误,因为我应该将整个代码放在一行中?
标签: reactjs react-native react-redux react-navigation