Reputation: 662
I'm currently stuck on the following issue.
I have this as my navigationOptions:
static navigationOptions = ({navigation}) => {
const { state, setParams } = navigation;
return {
title: 'Test',
headerRight: <Button title="Send" onPress={() => {
uploadImageAsync();
}}/>
};
};
I have a function called uploadImageAsync()
, when I try calling it from here I just get the error cannot find variable uploadImageAsync
. I've tried with this.uploadImageAsync()
too but to no avail.
Any help would be appreciated.
Upvotes: 0
Views: 192
Reputation: 498
The issue with the static navigationOptions
. You cant access this
or anything in your component from a static assignment. You will need to move this function to a redux call or a global function that can be used. You could also send it through the navigation props. This can be set through
this.props.navigation.navigate(
'NewPage',
{uploadImageAsync: uploadImageAsync}
/* ^- The assignment in a higher component from the navigate call*/
)
and then accessed through navigation.state.params.uploadImageAsync()
Upvotes: 1