yyg1378265336
2025-02-27 1384174f03c9a009cfbb3ae99aaeec21f177e4c2
src/components/Form/src/hooks/useComponentRegister.ts
@@ -1,9 +1,17 @@
import type { ComponentType } from '../types/index';
import type { ComponentType } from '../types';
import { tryOnUnmounted } from '@vueuse/core';
import { add, del } from '../componentMap';
import type { Component } from 'vue';
import { isPascalCase } from '@/utils/is';
export function useComponentRegister(compName: ComponentType, comp: Component) {
export function useComponentRegister<T extends string, R extends Component>(
  compName: ComponentType | T,
  comp: R,
) {
  if (!isPascalCase(compName)) {
    throw new Error('compName must be in PascalCase');
  }
  add(compName, comp);
  tryOnUnmounted(() => {
    del(compName);