如何通过静态navigationOptions将道具从前一个屏幕传递到下一个屏幕?

时间:2017-07-11 20:50:15

标签: javascript reactjs react-native react-redux react-navigation

我有这种屏幕转换:

  

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。其定义的语法错误说:

  

意外的令牌,预期,

会出现什么问题?感谢

1 个答案:

答案 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})} />

你错过了钥匙。