'undefined 不是对象(正在评估 'props.deviceLocale')

'undefined is not an object (evaluating 'props.deviceLocale')

我正在尝试通过单击“提交”按钮来验证文本字段。但我总是得到错误 -

TypeError: undefined 在我的模拟器上不是对象(正在评估 'props.deviceLocale')。

(我使用的是 Android 模拟器)。

但是我没有在我的代码中使用 'deviceLocale'。我不知道我的代码中是否需要它。

这是我的代码:

import React, {Component} from 'react';
import { View, Text, TouchableOpacity, TextInput } from 'react-native';
import ValidationComponent from 'react-native-form-validator';

export default class App extends ValidationComponent {
  
  constructor() {
    super()
    this.state = {
      name: "abc"
    }
  }

  _onPressButton() {
    this.validate({
      name: {minlength: 3, maxlength: 7, required: true},
    });
  }

  render() {
    return (

      <View>

        <TextInput 
          ref = "name"
          onChangeText = {(name) => this.setState({name})}
          value = {this.state.name}
        />

        <TouchableOpacity onPress = {this._onPressButton}>
          <Text>Submit</Text>
        </TouchableOpacity>

      </View>
    )
  }
}

错误快照:

你甚至在加载组件之前就得到了错误然后,请正确绑定你的 _onPressButton,然后至少你的组件将正确安装,然后你即将出现的错误将像使用 this.validate 对我来说有点模棱两可,因为我看不到组件中的 validate 函数。

要绑定您的 _onPressed,请如下声明:

_onPressButton = () => {
  this.validate({
    name: {minlength: 3, maxlength: 7, required: true},
  });
}

错误是因为 _onPressed 在您的组件安装后立即被调用。如果这有助于您至少在组件安装方面取得进展,请在评论中告诉我。

已编辑: 此外,您的构造函数不向超级构造函数提供道具,

声明如下:

 constructor(props) {
   super(props);
   this.state = {
     name: "abc"
   }
 }