2024-12-15 15:53:51 +08:00
|
|
|
import * as React 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
|
|
|
|
2024-12-15 15:53:51 +08:00
|
|
|
React.useEffect(() => {
|
2023-05-09 19:09:21 +08:00
|
|
|
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]);
|
|
|
|
}
|