【发布时间】:2018-09-10 16:37:38
【问题描述】:
我有一个父类
import React, { Component } from 'react';
import { View, TouchableOpacity, Text, ListView } from 'react-native';
import Profile from './UserBlock';
export default class ControlPanel extends Component {
constructor(props){
super(props)
console.log(this.props)
this.state = {
email: "email@gg.com",
first_name: "User",
image : '../img/user.png'
}
}
render() {
return(
<View style={{backgroundColor:'rgba(255,255,255,0.93)', flex:1,}}>
<Profile {...this.props} />
</View>)
}
}
和子组件
import React, { Component } from 'react';
import { View, Text, Image } from 'react-native';
export default class UserBlock extends Component {
constructor(props){
super(props)
this.state = {}
}
render() {
return(
<View style={{flexDirection:'row', padding:10}}>
<Image source ={{uri : this.props.state.image}} resizeMode="contain" style={{margin:15, width:60, height:60, borderRadius:30}} />
<View style ={{justifyContent:'center', margin:15}}>
<Text style={{fontWeight:'700', fontSize:25, color:'#444'}}>{this.props.state.first_name}</Text>
<Text style={{fontWeight:'200', color:'#999'}}>{this.props.state.email}</Text>
</View>
</View>)
}
}
但是当我尝试读取父道具时,我遇到了一个错误“TypeError: undefined is not an object”
但在我看来,我做的一切都是正确的。
【问题讨论】:
标签: reactjs react-native react-redux