React native ReactNative-从redux表单获取值

React native ReactNative-从redux表单获取值,react-native,redux,redux-form,React Native,Redux,Redux Form,我使用ReactNative+redux+redux形式 在我的login.js屏幕中,我有以下内容: function bindAction(dispatch) { return { actions: bindActionCreators(loginActions, dispatch) }; } function mapStateToProps(state) { return state.loginReducer } export default con

我使用ReactNative+redux+redux形式

在我的login.js屏幕中,我有以下内容:

function bindAction(dispatch) {
    return {
        actions: bindActionCreators(loginActions, dispatch)
    };
}
function mapStateToProps(state) {
    return state.loginReducer
}
export default connect(mapStateToProps, bindAction)(reduxForm({
    form: "login",
    initialValues: {
        email: "test@test.fr",
        password: "123123"
    }
})(LoginForm));
我的表格是:

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

const selector = formValueSelector("login")
我没有错误,但在
login()
函数中,我的字段总是空的

老实说,我读了文档,但我不知道如何正确使用redux表单。我需要使用其他东西来获取字段值?谢谢

**编辑**

关于一些示例,我现在使用以下代码:

<Button
    style={styles.loginBtn}
    disabled={this.props.loading}
    onPress={handleSubmit(this.login)}
>
...
</Button>

我不知道这是否是正确的方法,在react native中,我没有发现任何使用
元素的示例,但它是有效的。

在redux表单中,您可以使用函数将值传递给处理程序表单是有效的,或者使用函数获取表单值

handleSubmit

<Button
    style={styles.loginBtn}
    disabled={loading || !valid || pristine}
    onPress={handleSubmit(this.login)}
>
...
</Button>

login(data) {
  this.props.actions.loginUser({
    username: data.email,
    password: data.password
  });
}

...
登录(数据){
this.props.actions.login用户({
用户名:data.email,
密码:data.password
});
}
formValueSelector

const LoginForm = reduxForm({ // <== const Form Handler
  form: 'login', // <== Your Redux Form name
  initialValues: {
    email: "test@test.fr",
    password: "123123"
  }
})(Login); // <== Bind your Class Name here

const selector = formValueSelector('login') // <== Redux Form Name

const mapStateToProps = (state) => ({
  email: selector(state, 'email'),
  password: selector(state, 'password'),
});

export default connect(mapStateToProps)(LoginForm); // <== Bind the const Form Handler

const LoginForm=reduxForm({//表单提交时是否调用了登录函数?我将更新我的问题谢谢,这就是我在doc上看到的原因,但是如何将其与一个reducer结合起来?我有一个reducer(loginReducer),我不知道如何在
mapstatetops
功能中合并如果您的登录还原程序包含
email
password
等字段,那么您可以将
mapstatetops
中的字段合并为
const{email,password}=selector(state,'email',password'))
并将其作为
loginReducer:{…state.loginReducer,email,password}返回
<Button
    style={styles.loginBtn}
    disabled={loading || !valid || pristine}
    onPress={handleSubmit(this.login)}
>
...
</Button>

login(data) {
  this.props.actions.loginUser({
    username: data.email,
    password: data.password
  });
}
const LoginForm = reduxForm({ // <== const Form Handler
  form: 'login', // <== Your Redux Form name
  initialValues: {
    email: "test@test.fr",
    password: "123123"
  }
})(Login); // <== Bind your Class Name here

const selector = formValueSelector('login') // <== Redux Form Name

const mapStateToProps = (state) => ({
  email: selector(state, 'email'),
  password: selector(state, 'password'),
});

export default connect(mapStateToProps)(LoginForm); // <== Bind the const Form Handler