import type { ComponentProps, ComponentType } from "react"; import React, { useMemo, lazy, Suspense } from "react"; import { Platform } from "../Platform"; import { LoadSkiaWeb } from "./LoadSkiaWeb"; type NonOptionalKeys = { [k in keyof T]-?: undefined extends T[k] ? never : k; }[keyof T]; type WithSkiaProps = { fallback?: ComponentProps["fallback"]; getComponent: () => Promise<{ default: ComponentType }>; opts?: Parameters[0]; } & (NonOptionalKeys extends never ? { componentProps?: TProps; } : { componentProps: TProps; }); export const WithSkiaWeb = ({ getComponent, fallback, opts, componentProps, }: WithSkiaProps) => { const Inner = useMemo( // TODO: investigate // eslint-disable-next-line @typescript-eslint/no-explicit-any (): any => lazy(async () => { if (Platform.OS === "web") { await LoadSkiaWeb(opts); } else { console.warn( " is only necessary on web. Consider not using on native." ); } return getComponent(); }), // We we to run this only once. // eslint-disable-next-line react-hooks/exhaustive-deps [] ); return ( ); };