accounts-frontend/packages/app/components/ui/form/FormInputComponent.tsx
kotwys 4265b37543
Fix field errors view (fixes #23) (#29)
* Probably fixes #23

* Track field errors from state only

The previous commit has moved error storage to state so it isn't
necessary to check for error in props anymore.

* Undo state initialization from props
2020-08-05 14:58:31 +03:00

27 lines
610 B
TypeScript

import React from 'react';
import { MessageDescriptor } from 'react-intl';
import FormComponent from './FormComponent';
import FormError from './FormError';
import { ValidationError } from './FormModel';
type Error = ValidationError | MessageDescriptor;
export default class FormInputComponent<P, S = {}> extends FormComponent<
P & {
error?: Error;
},
S & {
error?: Error;
}
> {
renderError() {
return <FormError error={this.state?.error || this.props.error} />;
}
setError(error: Error) {
// @ts-ignore
this.setState({ error });
}
}