如何使用Field Redux表单发送道具

时间:2018-09-28 13:13:18

标签: reactjs react-native react-redux

我创建了一个组件,并且正在使用Redux-form字段,但是我无法将道具传递给他,我该怎么办?

我正在尝试使用睾丸

componet

renderInput({ input, label, type, meta: { touched, error, warning } }) {  
    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.props.teste(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>
    );
  }

我的领域

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

我的功能

onChangeTextDestino (param) {
  try {
    this.setState({strEmail: param})
    Alert.alert(this.state.strEmail)
  } catch (e) {
    console.log("error", e)
  }
}

我该怎么做才能传递道具的道具?

1 个答案:

答案 0 :(得分:1)

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

尝试类似这样的方法。 (https://redux-form.com/6.0.0-alpha.4/docs/api/field.md/#usage