useGetComponetConfig.ts 580 Bytes
import { createComponent } from '..';
import { transformComponentKey } from '../componentMap';
import { ConfigType, CreateComponentType, PublicComponentOptions } from '../index.type';

export const useGetComponentConfig = (
  key: string,
  options: Partial<PublicComponentOptions> = {}
): CreateComponentType => {
  try {
    const config = createComponent({ key: transformComponentKey(key) } as ConfigType, options);
    return config;
  } catch (error) {
    console.error(`can not get component config by component key (${key})`);
    return {} as CreateComponentType;
  }
};