mirror of
https://github.com/stashapp/stash.git
synced 2025-12-21 07:46:02 +01:00
23 lines
568 B
TypeScript
23 lines
568 B
TypeScript
import { lazy } from "react";
|
|
|
|
interface ILazyComponentError {
|
|
__lazyComponentError?: true;
|
|
}
|
|
|
|
export const isLazyComponentError = (e: unknown) => {
|
|
return !!(e as ILazyComponentError).__lazyComponentError;
|
|
};
|
|
|
|
export const lazyComponent = <Props extends object>(
|
|
factory: () => Promise<{ default: React.FC<Props> }>
|
|
) => {
|
|
return lazy(async () => {
|
|
try {
|
|
return await factory();
|
|
} catch (e) {
|
|
// set flag to identify lazy component loading errors
|
|
(e as ILazyComponentError).__lazyComponentError = true;
|
|
throw e;
|
|
}
|
|
});
|
|
};
|