Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6214

Passing in a Function with Parameters into a Child Component in React Native Typescript

$
0
0

I'm trying to pass the following function into a child component as a prop, along with a string parameter:

navigateToDetailsPage(nasaId: string) {  this.props.navigation.navigate('Details', {     nasaId: nasaId  })}

I pass in the function & parameter into the child component like so:

<NasaImage  onPress={this.navigateToDetailsPage(result.data[0].nasa_id)}  .../>

In the child component NasaImage I have declared onPress as:

onPress: () => void

However, I am getting the following error in the parent component:

Type 'void' is not assignable to type '() => void'.ts(2322)NasaImage.tsx(12, 3): The expected type comes from property 'onPress'


Viewing all articles
Browse latest Browse all 6214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>