我有这样的屏幕转换:
A -> B -> C
现在在 B 上,我有这个静态导航选项
:
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})} />
} );
// ...
}
我从A
接收MyString
,并在B
中正常显示。但我想通过单击 headerRight
按钮将其传递给 C
。其定义中存在语法错误:
Unexpected token, expected ,
会出现什么问题吗?谢谢
最佳答案
更改此行:
headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {navigation.state.params.MyString})} />
对于:
headerRight: <Button title="+" onPress={() => navigation.navigate('ScreenC', {title:navigation.state.params.MyString})} />
您缺少 key 。
关于javascript - 如何通过静态navigationOptions将 Prop 从上一个屏幕传递到下一个屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45044251/