mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-25 00:08:27 +08:00
d5abbad8f1
* refactor: deprecatedWraning * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code
23 lines
528 B
TypeScript
23 lines
528 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
import { devUseWarning } from '../../_util/warning';
|
|
import type { FormProps } from '../Form';
|
|
|
|
const names: Record<string, number> = {};
|
|
|
|
export default function useFormWarning({ name }: FormProps) {
|
|
const warning = devUseWarning('Form');
|
|
|
|
useEffect(() => {
|
|
if (name) {
|
|
names[name] = (names[name] || 0) + 1;
|
|
|
|
warning(names[name] <= 1, 'usage', 'There exist multiple Form with same `name`.');
|
|
|
|
return () => {
|
|
names[name] -= 1;
|
|
};
|
|
}
|
|
}, [name]);
|
|
}
|