Ega Setya Putra Ega Setya Putra - 22 days ago 10
iOS Question

How to call this.props from children class?

So I make a gallery for my app that allows user to get images from their social media account. I use Redux for my app..and I already save facebook ID and TOKEN on my app store when the user login. I have no problem when I called this.props.fbLoginData.TOKEN from parent class.. however I always get


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


when I called this.props from my children class.

here is my Gallery(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}
/>
);


}
}

and here is my 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}
/>
);
}


I've tried to bind this.props.fbLoginData.TOKEN but it will become empty.
How can I get fbLoginData state from fbPhotos class?

Answer

In your renderScene method :

_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;
  }
};