使用React Native的未定义导航器

时间:2018-04-28 14:18:30

标签: javascript reactjs react-native

我正在使用undefine navigator使用React Native

MessageTabs:

 _onPressItem = (item) => { 
  const { navigate } = this.props.navigation;

   //console.log(JSON.stringify(item));
  navigate('SingleConversation', {id: item.id})
};

在SingleConversation的构造函数中,我得到:

var conversation_id = this.navigation.state.params.id;

我正在

TypeError: Cannot read property 'state' of undefined

1 个答案:

答案 0 :(得分:1)

在SingleConversation的构造函数中:

constructor(props) {
  super(props);
  // `navigation` is from props, not `this`
  var conversation_id = props.navigation.state.params.id;
}