gpt4 book ai didi

ios - 如何从 child 类调用this.props?

转载 作者:行者123 更新时间:2023-11-29 00:35:49 25 4
gpt4 key购买 nike

因此,我为我的应用程序创建了一个图库,允许用户从其社交媒体帐户获取图像。我的应用程序使用 Redux。当用户登录时,我已经在我的应用程序商店中保存了 facebook ID 和 TOKEN。当我从父类调用 this.props.fbLoginData.TOKEN 时,我没有问题。但是我总是得到

undefined is not an object(evaluating 'this.props.fbLoginData.TOKEN')

当我从我的 child 类(class)调用 this.props 时。

这是我的画廊(父级)类(class):

_renderScene = ({ route }) => {
switch (route.key) {
case '1':
return <View style={styles.page} />;
case '2':
return <View style={styles.page} />;
case '3':
return <FBPhotos />;
default:
return null;
}
};

render() {
return (
<TabViewAnimated
style={[ styles.container, this.props.style ]}
navigationState={this.state}
renderScene={this._renderScene}
renderHeader={this._renderHeader}
onRequestChangeTab={this._handleChangeTab}
initialLayout={initialLayout}
/>
);

}

这是我的 fbPhotos 类

componentWillMount(){
//this._facebookPhotoIDs();
fbToken = this.props.fbLoginData.TOKEN;
}

render(){
return (
prop to style the items.
<ListView contentContainerStyle={styles.list}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
/>
);
}

我尝试绑定(bind) this.props.fbLoginData.TOKEN 但它会变空。如何从 fbPhotos 类获取 fbLoginData 状态?

最佳答案

在您的 renderScene 方法中:

_renderScene = ({ route }) => {
switch (route.key) {
case '1':
return <View style={styles.page} />;
case '2':
return <View style={styles.page} />;
case '3':
return <FBPhotos fbLoginData={this.props.fbLoginData} />;
default:
return null;
}
};

关于ios - 如何从 child 类调用this.props?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40649370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com