在native native中调用submit函数时,redux表单不返回任何内容

时间:2018-04-15 14:05:41

标签: react-native

我正在尝试使用react native创建一个简单的redux表单,但是当我调用submit函数时它返回一个空数组?

import React,{ Component } from 'react';
import { Field,reduxForm } from 'redux-form';
import { Text,Input } from 'react-native-elements';
import { View,Button } from 'react-native';
import {Icon,CheckBox} from 'react-native-elements';
 const renderField=({label,keyboardType,name,icon,iconType}) => {
    return(
            <View style={{flexDirection:'row'}}>
                <Input keyboardType={keyboardType} placeholder={label} inputContainerStyle={{borderWidth:2,borderColor:'lightgrey',borderRadius:20}} inputStyle={{color:'grey'}} leftIcon={<Icon size={25} type={iconType} name={icon} color="grey" />} errorStyle={{fontSize:15}} errorMessage="error" />
            </View>
    )
}
 const checkBoxField=({label,keyboardType,name}) => {
    return(
            <View style={{flexDirection:'row'}}>
                <Text>{label}</Text>
                <CheckBox  title='Male' checkedIcon='dot-circle-o' uncheckedIcon='circle-o' checked={true} containerStyle={{backgroundColor:'transparent',marginBottom:10}} />      
            </View>
    )
}

const submit=values=>{
    console.log(values)
}
const RegisterForm=props => {
    const {handleSubmit}=props;
    return(
            <View style={{flex:1,flexDirection:'column',margin:20,justifyContent:'flex-start',alignItems:'center'}}>

                <Field label="Username" component={renderField} name="username" icon="user" iconType="font-awesome" />
                <Field label="Email" component={renderField} name="email" icon="email" iconType="zocial" />
                <Field label="Gender" component={checkBoxField} name="gender" />
                <Button title='SUBMIT' onPress={handleSubmit(submit)} />

            </View>
    )
}
const Register=reduxForm({
    form:'register',

})(RegisterForm);
export default Register;

在上面的代码中单击提交按钮时,它将调用带参数的提交功能,但在控制台中不会打印任何内容。问题是什么?

1 个答案:

答案 0 :(得分:0)

当您按下提交按钮时,您使用提交函数调用props.handleSubmit(),但Button组件中的onPress()处理程序不接受任何参数。

所以你的submit()函数实际上从未被调用过。