SetState does not work inside component

0

Hello, I'm trying to get a setstate but when I run it it returns me which is not a function

renderInput({ input, label, type, meta: { touched, error, warning } }) {
    onChangeTextDestino = async (param) => {
      try {
        this.setState({strEmail: param})
        Alert.alert(this.state.strEmail)
      } catch (e) {
        console.log("error", e)
      }
    }

    return (
      <View>
        <Item error={error && touched} rounded style={styles.inputGrp}>
          <Icon
            active
            name={input.name === "email" ? "mail" : "unlock"}
            style={{ color: "#fff" }}
          />
          <Input
            ref={c => (this.textInput = c)}
            placeholderTextColor="#FFF"
            style={styles.input}
            placeholder={input.name === "email" ? "Email" : "Senha"}
            secureTextEntry={input.name === "password" ? true : false}   
            onChangeText={text => this.onChangeTextDestinos(text)}
            {...input}
          />
          {touched && error
            ? <Icon
              active
              style={styles.formErrorIcon}
              onPress={() => this.textInput._root.clear()}
              name="close"
            />
            : <Text />}
        </Item>
        {touched && error
          ? <Text style={styles.formErrorText1}>
            {error}
          </Text>
          : <Text style={styles.formErrorText2}>error here</Text>}
      </View>
    );
  }

This component is called this:

<Field
   name="email"
   component={this.renderInput}
   type="email"
   validate={[email, required]}
/>

How do I pass this function to the props?

component={this.renderInput}
    
asked by anonymous 27.09.2018 / 22:10

1 answer

0

In order to correct this problem, it was necessary to change the way in which I pass to the Faithful my component, thus:

const RenderInput = this.renderInput;
<Field component={(props) => <RenderInput {...props} onChangeTextDestinos={onChangeTextDestinos} />} />

and I started receiving in my component as a parameter:

onChangeTextDestinos
    
28.09.2018 / 19:01