Skip to content

Commit

Permalink
fix(components): update AsyncComponent TS interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyperkid123 committed Dec 13, 2024
1 parent 587afad commit 2b4d604
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions packages/components/src/AsyncComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import { ChromeAPI } from '@redhat-cloud-services/types';

export type ExcludeModulesKeys = 'module' | 'scope';

export type AsyncComponentProps = {
export type AsyncComponentProps<T extends object = object> = {
/** Loaded module, it has to start with `./`. */
module: string;
/** Optional scope, if not passed appName is used. */
scope: string;
/** React Suspense fallback component. <a href="https://reactjs.org/docs/code-splitting.html#reactlazy" target="_blank">Learn more</a>. */
fallback: React.ReactElement;
fallback?: React.ReactElement;
/** Optional wrapper component */
component: keyof JSX.IntrinsicElements;
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
component?: keyof JSX.IntrinsicElements;
} & React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> &
T;

type BaseAsyncComponentProps = AsyncComponentProps & {
innerRef: React.MutableRefObject<HTMLElement | null> | ((instance: HTMLElement | null) => void) | null;
Expand Down Expand Up @@ -56,6 +57,9 @@ const BaseAsyncComponent: React.FunctionComponent<BaseAsyncComponentProps> = ({
* This component uses fallback as ErrorComponent, if you want to show different
* component for error pass it as ErrorComponent prop.
*/
export const AsyncComponent = React.forwardRef<HTMLElement, AsyncComponentProps>((props, ref) => <BaseAsyncComponent innerRef={ref} {...props} />);
const InternalSyncComponent = React.forwardRef<HTMLElement, AsyncComponentProps>((props, ref) => <BaseAsyncComponent innerRef={ref} {...props} />);
export function AsyncComponent<T extends object = object>(props: AsyncComponentProps & T) {
return <InternalSyncComponent {...props} />;
}

export default AsyncComponent;
2 changes: 1 addition & 1 deletion packages/components/src/Inventory/TagWithDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type TagWithDialogProps = Omit<AsyncComponentProps, ExcludeModulesKeys>;
*/
const BaseTagWithDialog: React.FC<TagWithDialogProps & { innerRef?: React.Ref<HTMLElement>; history?: unknown; store?: unknown }> = (props) => {
const store = useStore();
const Cmp = props.component;
const Cmp = props.component ?? 'section';
const SCProps: ScalprumComponentProps<ChromeAPI, TagWithDialogProps> = {
history: props.history,
store,
Expand Down

0 comments on commit 2b4d604

Please sign in to comment.