2022-07-14 11:01:39 +08:00
|
|
|
import { useContext } from 'react';
|
|
|
|
import type { ValidateStatus } from 'antd/es/form/FormItem';
|
|
|
|
import { FormItemInputContext } from '../context';
|
|
|
|
import warning from '../../_util/warning';
|
|
|
|
|
|
|
|
type UseFormItemStatus = () => {
|
|
|
|
status?: ValidateStatus;
|
|
|
|
};
|
|
|
|
|
|
|
|
const useFormItemStatus: UseFormItemStatus = () => {
|
|
|
|
const { status } = useContext(FormItemInputContext);
|
|
|
|
|
|
|
|
warning(
|
|
|
|
status !== undefined,
|
|
|
|
'Form.Item',
|
2023-03-01 11:52:37 +08:00
|
|
|
'Form.Item.useStatus should be used under Form.Item component. For more information: https://u.ant.design/form-item-usestatus',
|
2022-07-14 11:01:39 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return { status };
|
|
|
|
};
|
|
|
|
|
2022-11-22 11:40:17 +08:00
|
|
|
// Only used for compatible package. Not promise this will work on future version.
|
|
|
|
(useFormItemStatus as any).Context = FormItemInputContext;
|
|
|
|
|
2022-07-14 11:01:39 +08:00
|
|
|
export default useFormItemStatus;
|