How to reset initial value in redux form

Sunil tc picture Sunil tc · Mar 10, 2017 · Viewed 31.6k times · Source

I'm using redux-form. I'm showing initial values in input fields from the state. When I click on reset, the input field is still showing initial values.

How can I reset the input field?

This is my code :

const mapStateToProps = (state) => {
    return {
        initialValues: {
            name:state.userInfo.data.name,
            email:state.userInfo.data.email,
            phone:state.userInfo.data.phone,
            city:state.userInfo.data.city.name,
        }
    };
}

This is how I'm calling initial value in the input field.

const renderField = ({ input, label, type, meta: { touched, error } }) => (
    <div>
        <input className="form-control control_new" {...input} placeholder={label} type={type}/>
    {touched && ((error && <span>{error}</span>))}
    </div>
)

<Field type="text" {...name} name="name" component={renderField} label="Enter Your Name" />

Thanks

Answer

Harsha W picture Harsha W · Mar 10, 2017
import {reset} from 'redux-form';

...

dispatch(reset('myForm'));  // requires form name