Skip to content

Deal with complex errors #222

@robinmolen

Description

@robinmolen

We now have multiple components with complex errors: file upload, children, partners, profile.

All have a similar complex setup:

const {error: formikError} = getFieldMeta(name);

// We can have individual file errors (because the intrinsic value type of the
// component is FileUploadData[]), a string error for the component as a whole or even
// deeply nested errors for a file in value array. The types from Formik are very wrong,
// which is why we need the cast. We also can't use the useFieldError hook because it's
// meant for components with a single/multiple mode, but file components *always* have an
// array of file uploads, even if multiple files are not allowed.
const error = formikError as unknown as
  | undefined
  | string
  | (string | FormikErrors<FileUploadData>)[];

This complex structure is needed because getFieldMeta() assumes error is always a string, which is not the case for these components.

We should implement a proper setup for dealing with these kinds of complex error structures. Like #213 (comment) suggested, perhaps a asComplexDataError hook, or extension on useFieldError, that deals with this complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions