Javascript 数据在其前面返回未定义的值´;s get´;数据是什么?
我真的不知道该怎么问这个问题,但我的问题是,在获取数据之前,标题需要返回未定义的数据。因此,即使我得到了数据,它也崩溃了,我如何解决这个问题Javascript 数据在其前面返回未定义的值´;s get´;数据是什么?,javascript,reactjs,firebase,react-native,Javascript,Reactjs,Firebase,React Native,我真的不知道该怎么问这个问题,但我的问题是,在获取数据之前,标题需要返回未定义的数据。因此,即使我得到了数据,它也崩溃了,我如何解决这个问题 componentWillMount () { this.props.fetchProfileData() } <Header style={{ padding: 0 }} backgroundColor='#1E1E1E' outerContainerStyles={{ height: 80 }} leftComponent
componentWillMount () {
this.props.fetchProfileData()
}
<Header
style={{ padding: 0 }}
backgroundColor='#1E1E1E'
outerContainerStyles={{ height: 80 }}
leftComponent={
<Avatar
small
rounded
source={console.log(this.props.profile[0])}
//onPress={this.toggleModal.bind(this)}
/>
}
centerComponent={{ text: 'People Out Tonight ', style: { color: '#fff', fontFamily: 'GeosansLight', fontSize: 15 } }}
rightComponent={{ icon: 'forum', color: '#fff' }}
/>
componentWillMount(){
this.props.fetchProfileData()
}
如果fetchProfileData
是异步的,我强烈建议您通过以下方式传递profile
的默认值:source={this.props.profile[0]|{}
或使用
如果不希望组件使用空的props进行渲染,则仅当fetchProfileData
完成或类似以下情况时才将其添加到DOM:render(){return({this.props.profile[0]&&&});}
错误信息是什么?为什么您的源代码控制台.log
?错误是“找不到这个.props.profile[0]”,我只是对它进行控制台操作,以便向您显示它获取了数据,但不是第一次呈现数据……我想您是通过网络请求获取这些数据的。请添加该代码,尤其是fetchProfileData()
中的代码。因为网络请求是异步的,所以您在第一次渲染时没有数据…您可以发布错误的屏幕截图吗?哪个元件和线给出了它?在fetchProfileData
完成之前,this.props.profile
是什么?componentDidMount可以。