ant-design/components/form/hooks/useFormItemStatus.ts
二货爱吃白萝卜 5cc338e177
refactor: All the warning set the warning type for future filter (#44613)
* feat: add warningContext

* refactor: part refactor

* chore: fix compile

* chore: part of it

* chore: part of it

* chore: part of it

* chore: fix lint

* chore: fix test

* chore: clean uo

* chore: hide warning def tmp

* chore: comment test

* chore: fix lint

* chore: refactor select icons

* chore: fix warning message

* test: update test

* chore: rm dead code
2023-09-11 17:28:04 +08:00

34 lines
990 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();
warning(
status !== undefined,
'Form.Item',
'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;