@ag04/react-utils
v1.0.1
Published
![npm version](https://img.shields.io/npm/v/@ag04/react-utils.svg?style=for-the-badge)
Downloads
10
Keywords
Readme
React utils
Documentation
parseFormErrors
Parses spring-form errors to redux-form error object.
VERSION 0.0.7
parseFormErrors(errors: FormFieldError[]): ParsedFormErrors
interface FormFieldError { defaultMessage: string, field: string }
type ParsedFormErrors = {
[fieldName: string]: string
}
👉 example
api.post("/foo", fooFormData)
.then(res => res.data)
.catch(e => {
// map spring form error arrray to redux-form error object
const errors = parseFormErrors(e.response.data.errors);
// show field errors in form
dispatch(reduxForm.stopSubmit(errors));
});
VERSION 1.0.0
parseFormErrors now expects object to have property "message" instead of "defaultMessage"