@ag04/react-utils

Parses spring-form errors to redux-form error object.

Usage no npm install needed!

<script type="module">
  import ag04ReactUtils from 'https://cdn.skypack.dev/@ag04/react-utils';
</script>

README

React utils

npm version

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"