How to get a link to a child component in a native reaction?

I had the installation of the ViewPager component in my react-native application that looks something like this:

 render(){ return( <View> <ViewPager ref="main" dataSource={this.state.dataSource} renderPage={this.renderView} /> <TouchableHighlight onPress={this._onPressButton}> <Text>Something</Text> </TouchableHighlight> </View> ); } renderView(){ return( <View ref="main1"> <Text>Something else</Text> </View> ); } _onPressButton(){ //Do something with {this.refs.main} and {this.refs.main1} } 

In the _onPressButton function _onPressButton I can access the ViewPager component using this.refs.main , but this.refs.main1 returns null . But I want to get a link to this view with a link to main1 . How can i do this?

+5
source share
1 answer

Declare refs as callbacks in each component:

 ref={(ref) => { this.main = ref; }} ref={(ref) => { this.main1 = ref; }} 

Then call the component as follows:

 this.main.main1 
0
source

All Articles