Clear Redux-Form Fields after submitting
Here is another Way of doing the same thing. - Redux provides a predefined method to handle submit called handleFormSubmit. You can basically do the same thing in that method as well, No need to use an extra method.
import React from "react";
import { reset, reduxForm } from "redux-form";
class Form extends React.Component {
onSubmit = (formValues, dispatch) => {
dispatch(reset("streamsForm")); // string here is the name of the form, check the export default reduxForm below.
};
render() {
return (
<form onSubmit={this.props.handleSubmit(this.onSubmit)}>
// Your Form related Fields
</form>
);
}
}
export default reduxForm({
form: "streamsForm"
})(Form);
You can use onSubmitSuccess with reset.
import { reset, reduxForm } from 'redux-form';
const afterSubmit = (result, dispatch) =>
dispatch(reset('ordersTradesSearchForm'));
const OrdersTradesSearchForm = reduxForm({
form: 'ordersTradesSearchForm',
onSubmitSuccess: afterSubmit,
})(OrdersTradesSearch);