vike-react 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,4 +8,4 @@ declare function ClientOnly<T>({ load, children, fallback, deps }: {
|
|
8
8
|
children: (Component: React.ComponentType<T>) => ReactNode;
|
9
9
|
fallback: ReactNode;
|
10
10
|
deps?: Parameters<typeof useEffect>[1];
|
11
|
-
}): React.JSX.Element;
|
11
|
+
}): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
|
@@ -1,12 +1,14 @@
|
|
1
1
|
export { ClientOnly };
|
2
|
-
import React, {
|
3
|
-
function ClientOnly({ load, children, fallback, deps }) {
|
2
|
+
import React, { lazy, useEffect, useState, startTransition } from 'react';
|
3
|
+
function ClientOnly({ load, children, fallback, deps = [] }) {
|
4
4
|
const [Component, setComponent] = useState(null);
|
5
5
|
useEffect(() => {
|
6
6
|
const loadComponent = () => {
|
7
7
|
const Component = lazy(() => load()
|
8
8
|
.then((LoadedComponent) => {
|
9
|
-
return {
|
9
|
+
return {
|
10
|
+
default: () => children('default' in LoadedComponent ? LoadedComponent.default : LoadedComponent)
|
11
|
+
};
|
10
12
|
})
|
11
13
|
.catch((error) => {
|
12
14
|
console.error('Component loading failed:', error);
|
@@ -14,7 +16,9 @@ function ClientOnly({ load, children, fallback, deps }) {
|
|
14
16
|
}));
|
15
17
|
setComponent(Component);
|
16
18
|
};
|
17
|
-
|
19
|
+
startTransition(() => {
|
20
|
+
loadComponent();
|
21
|
+
});
|
18
22
|
}, deps);
|
19
|
-
return
|
23
|
+
return Component ? React.createElement(Component, null) : fallback;
|
20
24
|
}
|