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

23 lines
528 B
TypeScript
Raw Normal View History

2023-05-09 19:09:21 +08:00
import { useEffect } 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');
2023-05-09 19:09:21 +08:00
useEffect(() => {
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]);
}