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

what is the proper return type for the "onPress" of my Navigation Button?

$
0
0

tsc is alerting me to add return types after the render method, and after onPress of my class component.

I've tried using React.ReactNode as the render return type, which makes the alert go away, but React.ReactChild also works (what's the difference? )

For the onPress event, i've tried void, which makes the return type happy, but I'm unsure if this is the correct return type to enter.

I've looked at the typescript cheatsheet on Github, but I can't find the opinionated definitive way.

export interface Props {
  navigation;
}

class HomeScreen extends React.Component<Props> {
  render(): React.ReactNode { // HERE
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
        <Button title="Go to Details" onPress={(): void =>  this.props.navigation.navigate('Details')} /> // HERE 
      </View>
    );
  }
}

Viewing all articles
Browse latest Browse all 6208

Trending Articles



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