Skip to content

Commit

Permalink
fix(🌎): componentProps prop to WithSkiaWeb (#2662)
Browse files Browse the repository at this point in the history
Co-authored-by: Santiago Topolansky <[email protected]>
  • Loading branch information
santitopo and santiagotopolansky-oneapp authored Sep 30, 2024
1 parent 8f016e9 commit 4c8fd33
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/skia/src/web/WithSkiaWeb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@ import { Platform } from "../Platform";

import { LoadSkiaWeb } from "./LoadSkiaWeb";

interface WithSkiaProps {
type NonOptionalKeys<T> = {
[k in keyof T]-?: undefined extends T[k] ? never : k;
}[keyof T];

type WithSkiaProps<TProps> = {
fallback?: ComponentProps<typeof Suspense>["fallback"];
getComponent: () => Promise<{ default: ComponentType }>;
getComponent: () => Promise<{ default: ComponentType<TProps> }>;
opts?: Parameters<typeof LoadSkiaWeb>[0];
}
} & (NonOptionalKeys<TProps> extends never
? {
componentProps?: TProps;
}
: {
componentProps: TProps;
});

export const WithSkiaWeb = ({
export const WithSkiaWeb = <TProps extends object>({
getComponent,
fallback,
opts,
}: WithSkiaProps) => {
componentProps,
}: WithSkiaProps<TProps>) => {
const Inner = useMemo(
// TODO: investigate
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -34,7 +45,7 @@ export const WithSkiaWeb = ({
);
return (
<Suspense fallback={fallback ?? null}>
<Inner />
<Inner {...componentProps} />
</Suspense>
);
};

0 comments on commit 4c8fd33

Please sign in to comment.