react-solidlike 2.5.2 → 2.5.3
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.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export { Await, type AwaitProps } from "./Await";
|
|
2
|
+
export { ClientOnly, type ClientOnlyProps } from "./ClientOnly";
|
|
2
3
|
export { Dynamic, type DynamicProps } from "./Dynamic";
|
|
3
4
|
export { ErrorBoundary, type ErrorBoundaryProps } from "./ErrorBoundary";
|
|
4
5
|
export { For, type ForProps } from "./For";
|
|
6
|
+
export { Once, type OnceProps } from "./Once";
|
|
5
7
|
export { QueryBoundary, type QueryBoundaryProps, type QueryResult } from "./QueryBoundary";
|
|
6
8
|
export { Repeat, type RepeatProps } from "./Repeat";
|
|
7
9
|
export { Show, type ShowProps } from "./Show";
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,16 @@ function Await({ promise, loading = null, error = null, children }) {
|
|
|
43
43
|
return children;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function ClientOnly({ children, fallback = null }) {
|
|
47
|
+
const [isClient, setIsClient] = useState(false);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
setIsClient(true);
|
|
50
|
+
}, []);
|
|
51
|
+
if (!isClient) return typeof fallback === "function" ? fallback() : fallback;
|
|
52
|
+
if (typeof children === "function") return children();
|
|
53
|
+
return children;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
function Dynamic({ component, fallback = null, ...props }) {
|
|
47
57
|
if (!component) return typeof fallback === "function" ? fallback() : fallback;
|
|
48
58
|
return createElement(component, props);
|
|
@@ -88,6 +98,18 @@ function For({ each, children, keyExtractor, fallback = null, wrapper, reverse }
|
|
|
88
98
|
return wrapper && isValidElement(wrapper) ? cloneElement(wrapper, {}, elements) : elements;
|
|
89
99
|
}
|
|
90
100
|
|
|
101
|
+
function Once({ children }) {
|
|
102
|
+
const cachedRef = useRef({
|
|
103
|
+
rendered: false,
|
|
104
|
+
content: null
|
|
105
|
+
});
|
|
106
|
+
if (!cachedRef.current.rendered) {
|
|
107
|
+
cachedRef.current.rendered = true;
|
|
108
|
+
cachedRef.current.content = children;
|
|
109
|
+
}
|
|
110
|
+
return cachedRef.current.content;
|
|
111
|
+
}
|
|
112
|
+
|
|
91
113
|
function defaultIsEmpty(data) {
|
|
92
114
|
if (data == null) return true;
|
|
93
115
|
if (Array.isArray(data)) return data.length === 0;
|
|
@@ -250,4 +272,4 @@ function Visible({ children, fallback = null, rootMargin = "0px", threshold = 0,
|
|
|
250
272
|
});
|
|
251
273
|
}
|
|
252
274
|
|
|
253
|
-
export { Await, Default, Dynamic, ErrorBoundary, For, Match, QueryBoundary, Repeat, Show, Split, Switch, Timeout, Visible };
|
|
275
|
+
export { Await, ClientOnly, Default, Dynamic, ErrorBoundary, For, Match, Once, QueryBoundary, Repeat, Show, Split, Switch, Timeout, Visible };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-solidlike",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.3",
|
|
4
4
|
"description": "Declarative React control flow components inspired by Solid.js, replacing ternary expressions and array.map() in JSX",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@types/react-dom": "^19.2.3",
|
|
54
54
|
"react": "^19.2.3",
|
|
55
55
|
"react-dom": "^19.2.3",
|
|
56
|
-
"rolldown": "^1.0.0-rc.
|
|
56
|
+
"rolldown": "^1.0.0-rc.3",
|
|
57
57
|
"typescript": "^5.9.3"
|
|
58
58
|
}
|
|
59
59
|
}
|