如何从 children class 调用 this.props?
How to call this.props from children class?
所以我为我的应用制作了一个图库,允许用户从他们的社交媒体帐户获取图片。我将 Redux 用于我的应用程序……并且当用户登录时,我已经在我的应用程序商店中保存了 facebook ID 和 TOKEN。当我从 parent class 调用 this.props.fbLoginData.TOKEN 时没有问题。但是我总是得到
undefined is not an object(evaluating 'this.props.fbLoginData.TOKEN')
当我从 children class 呼叫 this.props 时。
这是我的画廊(Parent) 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 class
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}
/>
);
}
我试过绑定 this.props.fbLoginData.TOKEN 但它会变成空的。
如何从 fbPhotos class 获取 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;
}
};
所以我为我的应用制作了一个图库,允许用户从他们的社交媒体帐户获取图片。我将 Redux 用于我的应用程序……并且当用户登录时,我已经在我的应用程序商店中保存了 facebook ID 和 TOKEN。当我从 parent class 调用 this.props.fbLoginData.TOKEN 时没有问题。但是我总是得到
undefined is not an object(evaluating 'this.props.fbLoginData.TOKEN')
当我从 children class 呼叫 this.props 时。
这是我的画廊(Parent) 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 class
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}
/>
);
}
我试过绑定 this.props.fbLoginData.TOKEN 但它会变成空的。 如何从 fbPhotos class 获取 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;
}
};