ant-design/components/form/hooks/useFormWarning.ts

23 lines
531 B
TypeScript
Raw Normal View History

import * as React from 'react';
import { devUseWarning } from '../../_util/warning';
2023-05-09 19:09:21 +08:00
import type { FormProps } from '../Form';
const names: Record<string, number> = {};
export default function useFormWarning({ name }: FormProps) {
const warning = devUseWarning('Form');
React.useEffect(() => {
2023-05-09 19:09:21 +08:00
if (name) {
names[name] = (names[name] || 0) + 1;
warning(names[name] <= 1, 'usage', 'There exist multiple Form with same `name`.');
2023-05-09 19:09:21 +08:00
return () => {
names[name] -= 1;
};
}
}, [name]);
}