【发布时间】:2020-05-01 09:31:09
【问题描述】:
我有一个简单的容器组件,它应该在某些时候处理一些逻辑:
import React, {Component} from 'react';
import {Text, View, Button, Image} from 'react-native';
import Title from '../Presentational/Title';
class AppList extends React.Component {
render() {
return (
<Title titleProperty={'To Do Something'}></Title>
);
}
}
export default AppList;
我尝试将一些 props 传递给 Title 组件,以便该组件显示它们:
import React, {Component} from 'react'
import {View, Text, StyleSheet} from 'react-native'
export default class Title extends React.Component {
render() {
const {children} = this.props.titleProperty;
return (
<View style = {styles.header}>
<Text style={styles.title}>{children}</Text>
</View>
)
}
}
const styles = StyleSheet.create({
header: {
backgroundColor: 'skyblue',
padding: 15,
},
title: {
textAlign: 'center',
color: 'white',
},
})
我得到的结果是一个没有任何文字的蓝条
为什么它不起作用?
【问题讨论】:
-
尝试在声明中删除
children周围的花括号。比如const children = this.props.titleProperty。
标签: javascript reactjs react-native