Javascript “反应本机”;这";关键字未定义

Javascript “反应本机”;这";关键字未定义,javascript,reactjs,react-native,jsx,Javascript,Reactjs,React Native,Jsx,所以我想使用this.props.navigation.navigate(),我收到一条错误消息,说未定义。 在阅读stockOverflow之后,我发现我需要像这样声明一个构造函数 constructor(props) { super(props); } 然而,这不断给我一个错误,说“;”是预期的,无论我做什么,这里是我的代码的简化版本 const activityStyles = ActivitiesStyles.createStyles() export default

所以我想使用
this.props.navigation.navigate()
,我收到一条错误消息,说未定义。 在阅读stockOverflow之后,我发现我需要像这样声明一个构造函数

constructor(props) {
    super(props);
    }
然而,这不断给我一个错误,说“;”是预期的,无论我做什么,这里是我的代码的简化版本

const activityStyles = ActivitiesStyles.createStyles()
export default (props) => {
    const {item: event, sensorID, homeInfo} = props

  return (
<View style={activityStyles.linkContent} underlayColor={Colors.navigationBkgdActive}>
    <View style={{flex: 0.60, flexDirection: 'row'}}>
        <TouchableHighlight onPress={(event)=>{this.props.navigation.navigate("WalkThru")}}>
            <SensorIcon style={iconStyle} size={Typography.bodyLineHeight} type={event.type} />
        </TouchableHighlight>
        <TextInput
            placeholder={event.type}
            autoCapitalize={true}
            style={activityStyles.text}>
        </TextInput>
    </View>
</View>
 )

}
const activityStyles=activityStyles.createStyles()
导出默认值(道具)=>{
const{item:event,sensorID,homeInfo}=props
返回(
{this.props.navigation.navigate(“WalkThru”)}>
)
}

正如Emile Bergeron所建议的,您应该使用道具,因为该关键字仅适用于基于类的组件

基于类的组件如下所示

export default class componentName extends Component {
  constructor(props) {
    super(props)

    this.state = {

    }
  }

  render() {
    return (
        <TouchableHighlight
          <View style={activityStyles.linkContent} underlayColor={Colors.navigationBkgdActive}>
            <TouchableHighlight onPress={(event)=>{this.props.navigation.navigate("WalkThru")}}>
              <SensorIcon style={iconStyle} size={Typography.bodyLineHeight} type={event.type} />
            </TouchableHighlight>
              <TextInput
                placeholder={event.type}
              </TextInput>
          </View>
        </TouchableHighlight>
    )
  }
}
导出默认类componentName扩展组件{
建造师(道具){
超级(道具)
此.state={
}
}
render(){
返回(

你忘了结束
。与
触控突出显示
相同,函数组件中没有有效的
。只需使用你收到的
道具作为参数。Emile Bergeron你能解释一下吗?这意味着没有“此”,也不需要“道具”是一个参数,不是实例属性。只需删除
这个。
并保留以下
道具。导航。导航(“WalkThru”)
,就是这样。我肯定会研究一下,但这实际上不起作用
导出默认值(道具)=>{
是有效的,因为我还有一些其他值在那之后使用道具