Reputation: 11424
I am using the StackNavigator
library but cannot figure out how to access the props from within navigationOptions.
In my calling class I have:
navigate("TestView", { mdata: mdataObject })
In my TestView class I have the following:
static navigationOptions = {
title: this.props.navigation.state.params.mdata.title
}
However, I get the following error:
Cannot find property 'navigation' of undefined
I have confirmed that I can access this.props.navigation.state.params.mdata.title
from the componentDidMount() function so there is data there.
Why am I getting this error from within the navigationOptions function and what can I do to fix it?
Also, I called navigateOptions a function, but not sure that is correct. What should I be calling it?
Upvotes: 1
Views: 1524
Reputation: 1417
Access navigation props at navigationOptions:
static navigationOptions = ({ navigation }) => ({
title: navigation.state.params.mdata.title // your case
})
Upvotes: 6