Skip to content

Commit

Permalink
fix(conditional container): error render fallback
Browse files Browse the repository at this point in the history
\
  • Loading branch information
tutods committed Sep 10, 2023
1 parent ef55623 commit a97a8ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ const ConditionalContainer = <TRender extends RenderElement, TFallback extends R
if (!when && fallback) {
const { element: fallbackElement, props: fallbackProps = {} } = fallback;

// If (typeof fallbackElement === 'string') {
return createElement(fallbackElement, fallbackProps, children);
// }
if (typeof fallbackElement === 'string') {
return createElement(fallbackElement, fallbackProps, children);
}

// Return fallbackElement({ ...fallbackProps, children });
return fallbackElement({ ...fallbackProps, children });
}

// When no `fallback` element is specified
Expand Down
17 changes: 11 additions & 6 deletions packages/components/src/components/ConditionalContainer/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import type { ComponentProps, FunctionComponent, JSX, ReactNode } from 'react';
import type {
ComponentProps,
ForwardRefExoticComponent,
JSX,
ReactElement,
ReactNode,
} from 'react';

/**
* Available types to be used on `render` or `otherwise`
*/
// TS will infer the props when `element` is defined
type RenderElement = FunctionComponent<any> | keyof JSX.IntrinsicElements;
/*
* | ((props: any) => ReactElement)
* | ForwardRefExoticComponent<any>
*/
type RenderElement =
| keyof JSX.IntrinsicElements
| ((props: any) => ReactElement)
| ForwardRefExoticComponent<any>;

type ComponentArgs<T extends RenderElement> = {
/**
Expand Down

0 comments on commit a97a8ca

Please sign in to comment.