mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-16 05:58:26 +02:00

* fix(import): ensure code convention compliance by importing React * fix(type): add generic type for useMemo
22 lines
531 B
TypeScript
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]);
|
|
}
|