这是React Native的保留字

时间:2018-10-29 21:08:37

标签: react-native react-redux

我一直在尝试渲染此图像。但是,始终会出现这是保留字的错误。它说第170行,它等于return语句中的函数{this.onRenderValidation(validation)}。有人知道我做错了吗? 谢谢你们!

onRenderValidation(validation){


  <Card>

    <CardSection>
      <Input
        label="Email"
        placeholder="email@gmail.com"
        onChangeText={this.onEmailChange.bind(this)}
        value={this.props.email}
      />
    </CardSection>
    <Text>
    {this.renderValidationError(validation.email)}
    </Text>
    <CardSection>
      <Input
        secret={true}
        label="Passwort"
        placeholder="password"
        onChangeText={this.onPasswordChange.bind(this)}
        value={this.props.password}
      />
    </CardSection>
    <Text>
    {this.renderValidationError(validation.password)}
    </Text>
    //{this.renderError()}

    <CardSection>
      {this.renderButton()}
    </CardSection>
    <CardSection>
      {this.render2Button()}
    </CardSection>
  </Card>

}

render(){
let validation=this.submitted ? this.validator.validate(this.state) : 
this.state.validation;
return(

   {this.onRenderValidation(validation)}

)
}
}

1 个答案:

答案 0 :(得分:0)

问题是您要返回一个对象,而不是JSX元素。只需将其更改为:

render(){
    let validation = this.submitted ? this.validator.validate(this.state) : this.state.validation;
    return this.onRenderValidation(validation);
}

或者,将其包装在JSX元素中:

render(){
    let validation = this.submitted ? this.validator.validate(this.state) : this.state.validation;
    return (
      <div>{this.onRenderValidation(validation)}</div>
    )
}

有关发生这种情况的更多信息,请在此处查看类似的问题以及最佳答案:React.js - Syntax error: this is a reserved word in render() function