Setstate does not work within component

Asked

Viewed 167 times

0

Hello, I’m trying to give a setstate but when I run it returns me that 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 so :

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

How do I pass that function to props?

component={this.renderInput}
  • Is this really the code? How are you exporting the methods? Are they separate files? Could you detail a little more

  • The code is really this, in the main class we have Field, and we created the renderInput component to pass as parameter to that field...

  • Jrd, the real problem is here https://stackoverflow.com/questions/52556195/how-send-props-using-field-redux-form

1 answer

0


To correct this problem it was necessary to change the form in which I pass to the Faithful my component, getting like this:

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

and I started receiving in my component as a parameter :

onChangeTextDestinos

Browser other questions tagged

You are not signed in. Login or sign up in order to post.