ant-design/components/form/hooks/useFormWarning.ts
kiner-tang(文辉) d5abbad8f1
refactor: deprecatedWarning (#44791)
* 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
2023-09-13 22:07:33 +08:00

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]);
}