fix: should throw warning only once, ref: #3491

This commit is contained in:
Benjy Cui 2016-10-21 11:03:22 +08:00
parent 7483254df6
commit 0aca663092

View File

@ -32,6 +32,7 @@ export interface FormItemContext {
form: WrappedFormUtils;
}
let autoGenerateWarning = false;
export default class FormItem extends React.Component<FormItemProps, any> {
static defaultProps = {
hasFeedback: false,
@ -60,11 +61,14 @@ export default class FormItem extends React.Component<FormItemProps, any> {
context: FormItemContext;
componentDidMount() {
warning(
!(this.getControls(this.props.children, true).length > 1),
'`Form.Item` cannot generate `validateStatus` and `help` automatically, ' +
'while there are more than one `getFieldDecorator` in it.'
);
if (!autoGenerateWarning && (this.getControls(this.props.children, true).length > 1)) {
autoGenerateWarning = true;
warning(
false,
'`Form.Item` cannot generate `validateStatus` and `help` automatically, ' +
'while there are more than one `getFieldDecorator` in it.'
);
}
}
shouldComponentUpdate(...args) {