Here is a demo of my issue: https://stackblitz.com/edit/redux-form-reset-problems
I am using redux-form 7.2.0 and am trying to reset the form values from another component that is not wrapped by the ReduxForm HOC.
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { reset } from 'redux-form';
class MoodAnnouncement extends Component {
constructor(props) {
super(props);
this.resetMood = this.resetMood.bind(this, event);
}
resetMood(event) {
event.preventDefault();
this.props.dispatch(this.props.reset('SearchFiltersForm'));
}
render() {
return (
<div className="mui-panel">
<button
className="mui-btn mui-btn--primary mui-btn--raised"
disabled={this.props.MoodCheckerForm.values === undefined}
onClick={this.resetMood}
>Reset Mood
</button>
</div>
);
}
}
const mapStateToProps = state => {
return {
MoodCheckerForm: state.form.MoodCheckerForm,
};
};
export default connect(mapStateToProps, { reset })(MoodAnnouncement);
When I click the reset mood button that is in another component away from the form, I'm receiving the error this.props.dispatch is not a function, so I assume there is a different way to dispatch the reset action from within the connect HOC.
How can I reset the form values from another component that is using the react-redux connect HOC?