我有这种屏幕转换:
A - > B - > ç
现在在B上,我有static navigationOptions
:
class ScreenB extends Component {
static navigationOptions = ({navigation}) => ({
/* works fine to display props here -> */ title: navigation.state.params.MyString, // works fine for display
headerLeft: <Button title="<" onPress={() => navigation.goBack()} />,
/* does not work to pass it here -> */ headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {navigation.state.params.MyString})} />
} );
// ...
}
我从MyString
收到A
,并在B
中正常显示。但我想在C
按钮点击时将其传递给headerRight
。其定义的语法错误说:
意外的令牌,预期,
会出现什么问题?感谢
答案 0 :(得分:1)
更改此行:
headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {navigation.state.params.MyString})} />
有关:
headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {title:navigation.state.params.MyString})} />
你错过了钥匙。