import React, { lazy, Suspense, useCallback, useEffect, type FC } from 'react'; import type { ControlledProps } from 'react-medium-image-zoom'; import { useControllable } from '@wener/reaction'; export type ZoomProps = { active?: boolean; onActiveChange?: (v: boolean) => void; } & Omit; const Controlled = lazy(() => import('react-medium-image-zoom').then(({ Controlled }) => ({ default: Controlled }))); export const Zoom: FC = ({ active, onActiveChange, children, ...props }) => { const [isZoomed, onZoomChange] = useControllable(active, onActiveChange, false); useEffect(() => { import('react-medium-image-zoom/dist/styles.css').catch((err) => { console.error('Failed to load react-medium-image-zoom styles', err); }); }, []); return ( { onZoomChange(v); }, [])} > {children} ); }; function useInjectScript(fn: () => Promise<{ default: any }>) { const [content, setContent] = React.useState(null); useEffect(() => { fn().then((v) => { setContent(v.default); }); }, []); } interface Module { [Symbol.toStringTag]: 'Module'; default?: any; [k: string | symbol]: any; }