You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
474 B
TypeScript
20 lines
474 B
TypeScript
2 years ago
|
import { useEffect } from 'react';
|
||
|
import warning from '../../_util/warning';
|
||
|
import type { FormProps } from '../Form';
|
||
|
|
||
|
const names: Record<string, number> = {};
|
||
|
|
||
|
export default function useFormWarning({ name }: FormProps) {
|
||
|
useEffect(() => {
|
||
|
if (name) {
|
||
|
names[name] = (names[name] || 0) + 1;
|
||
|
|
||
|
warning(names[name] <= 1, 'Form', 'There exist multiple Form with same `name`.');
|
||
|
|
||
|
return () => {
|
||
|
names[name] -= 1;
|
||
|
};
|
||
|
}
|
||
|
}, [name]);
|
||
|
}
|