mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-24 07:28:28 +08:00
d5abbad8f1
* refactor: deprecatedWraning * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code
33 lines
982 B
TypeScript
33 lines
982 B
TypeScript
import { useContext } from 'react';
|
|
import type { ValidateStatus } from 'antd/es/form/FormItem';
|
|
|
|
import { devUseWarning } from '../../_util/warning';
|
|
import { FormItemInputContext } from '../context';
|
|
|
|
type UseFormItemStatus = () => {
|
|
status?: ValidateStatus;
|
|
errors: React.ReactNode[];
|
|
warnings: React.ReactNode[];
|
|
};
|
|
|
|
const useFormItemStatus: UseFormItemStatus = () => {
|
|
const { status, errors = [], warnings = [] } = useContext(FormItemInputContext);
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
const warning = devUseWarning('Form.Item');
|
|
|
|
warning(
|
|
status !== undefined,
|
|
'usage',
|
|
'Form.Item.useStatus should be used under Form.Item component. For more information: https://u.ant.design/form-item-usestatus',
|
|
);
|
|
}
|
|
|
|
return { status, errors, warnings };
|
|
};
|
|
|
|
// Only used for compatible package. Not promise this will work on future version.
|
|
(useFormItemStatus as any).Context = FormItemInputContext;
|
|
|
|
export default useFormItemStatus;
|