refactor(client): optimize suspense components

Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
2026-01-01 10:38:57 +08:00
committed by Asai Neko
parent 4c438cf4e4
commit b5b4bb9d66
7 changed files with 99 additions and 34 deletions

View File

@@ -0,0 +1,20 @@
import type { ReactNode } from 'react';
import React, { Suspense } from 'react';
export function withFallback<P extends object>(
Component: React.ComponentType<P>,
fallback: ReactNode,
) {
const Wrapped: React.FC<P> = (props) => {
return (
<Suspense fallback={fallback}>
<Component {...props} />
</Suspense>
);
};
Wrapped.displayName = `withFallback(${Component.displayName! || Component.name || 'Component'
})`;
return Wrapped;
}