We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a5e752b commit 4a086f4Copy full SHA for 4a086f4
client.tsx
@@ -1,5 +1,6 @@
1
-import { useEffect, useState } from "react";
+import { lazy as oldLazy, useEffect, useState } from "react";
2
3
+/** @deprecated use lazy with suspense */
4
export function NoSSR({
5
children,
6
fallback,
@@ -11,3 +12,15 @@ export function NoSSR({
11
12
useEffect(() => setState(children), [children]);
13
return <>{state}</>;
14
}
15
+
16
+export function lazy<T>(
17
+ importFunc: () => Promise<{ default: React.ComponentType<T> }>
18
+): React.ComponentType<T> {
19
+ const LazyComponent = oldLazy(importFunc);
20
+ return (props: any) => {
21
+ if (typeof window === "undefined") {
22
+ throw new Error("client only");
23
+ }
24
+ return <LazyComponent {...props} />;
25
+ };
26
+}
0 commit comments