ant-design/components/form/hooks/useFormItemStatus.ts
MadCcc aca2c3d4e7
feat: add Form.Item.useStatus (#36486)
* feat: add useFormItemStatus

* chore: code clean

* docs: update example

* refactor: api change

* docs: fix typo

* docs: update docs

* docs: udpate

* chore: add warning

* test: add test case

* chore: update warning

* chore: code clean

* test: fix test case
2022-07-14 11:01:39 +08:00

23 lines
668 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 };
};
export default useFormItemStatus;