mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
26 lines
811 B
TypeScript
26 lines
811 B
TypeScript
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',
|
|
`Form.Item.useStatus should be used under Form.Item component. For more information: ${window.location.protocol}//${window.location.host}/components/form-cn/#Form.Item.useStatus`,
|
|
);
|
|
|
|
return { status };
|
|
};
|
|
|
|
// Only used for compatible package. Not promise this will work on future version.
|
|
(useFormItemStatus as any).Context = FormItemInputContext;
|
|
|
|
export default useFormItemStatus;
|