2023-05-09 19:09:21 +08:00
|
|
|
import { useEffect } from 'react';
|
2023-09-11 17:28:04 +08:00
|
|
|
|
|
|
|
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) {
|
2023-09-13 22:07:33 +08:00
|
|
|
const warning = devUseWarning('Form');
|
2023-09-11 17:28:04 +08:00
|
|
|
|
2023-05-09 19:09:21 +08:00
|
|
|
useEffect(() => {
|
|
|
|
if (name) {
|
|
|
|
names[name] = (names[name] || 0) + 1;
|
|
|
|
|
2023-09-13 22:07:33 +08:00
|
|
|
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]);
|
|
|
|
}
|