mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-04 20:49:41 +05:30
4265b37543
* 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
27 lines
610 B
TypeScript
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 });
|
|
}
|
|
}
|