ant-design/components/form/hooks/useFormWarning.ts
이선재 93ec292961
chore(import): ensure code convention compliance by importing React (#52021)
* fix(import): ensure code convention compliance by importing React

* fix(type): add generic type for useMemo
2024-12-15 15:53:51 +08:00

22 lines
531 B
TypeScript

import * as React 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');
React.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]);
}