React-Redux-Form远程提交

时间:2018-10-21 21:29:55

标签: javascript reactjs react-redux redux-form

我正在尝试使用redux-forms远程提交表单。我的问题是,如何从组件外部的函数执行redux动作。等同于:

  

this.props.action(params);

我的代码如下:

async function submit(values) {
    return (
        //Equivalent of => this.props.addOne(values.name)
        await actions.addOne(values.name, 60)
    )
}

const renderTextField = ({ input, label, meta: { touched, error } }) =>
<TextField 
    autoFocus
    margin="dense"
    fullWidth
    type="text"
    label={label}
    {...input}
/>

class LibrarySubsectionForm extends React.Component {
render() {
    const { handleSubmit } = this.props;

    return (
        <form onSubmit={handleSubmit}>
            <Field
                component={renderTextField}
                name="name" 
                label="Subsection Name"
            />
        </form>
    )
}
}

export default compose(
connect(null, actions),
reduxForm({ form: 'AddSubsection', onSubmit: submit })
)(LibrarySubsectionForm);

1 个答案:

答案 0 :(得分:2)

Redux形式将@GET("/") fun getInfo(@Query("pew") pew1: Double, @Query("pew2") pew2: Double): Single<PewResponse> override fun getResultFromNetwork() { pewService .getInfo("pew1","pew2") .subscribeOn(Schedulers.io()) // for background processing .observeOn(AndroidSchedulers.mainThread()) // get result in Main Thread (it require rxAndroid lib) .subscribe( { pewResponse -> // parse response and fill list }, { // handle error } ) } 函数和修饰组件的dispatch作为props处理程序的第二个和第三个参数传递。因此,基本上,您可以在onSubmit函数中访问它们。如果您将submit作为对actions的支持,则可以在LibrarySubsectionForm函数中访问它们:

submit