Skip to content

Commit a21ee05

Browse files
committed
feat: add solid-2 app demo
1 parent 5ff6e1a commit a21ee05

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ steps.
1111
* [Preact 10](./preact-10/)
1212
* [Remix 3](./remix-3/)
1313
* [Solid 1](./solid-1/)
14+
* [Solid 2](./solid-2/)
1415
* [Svelte 5](./svelte-5/)
1516
* [Vue 3](./vue-3/)

solid-2/deno.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"imports": {
3+
"@solidjs/signals": "https://esm.sh/*@solidjs/signals@0.11.1?dev",
4+
"@solidjs/web": "https://esm.sh/*@solidjs/web@2.0.0-beta.0?dev",
5+
"solid-js": "https://esm.sh/*solid-js@2.0.0-beta.0?dev",
6+
"solid-js/": "https://esm.sh/*solid-js@2.0.0-beta.0&dev/"
7+
}
8+
}

solid-2/index.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Buildless SolidJS 1 app</title>
7+
<script type="importmap">
8+
{
9+
"imports": {
10+
"@solidjs/signals": "https://esm.sh/*@solidjs/signals@0.11.1?dev",
11+
"@solidjs/web": "https://esm.sh/*@solidjs/web@2.0.0-beta.0?dev",
12+
"solid-js": "https://esm.sh/*solid-js@2.0.0-beta.0?dev",
13+
"solid-js/": "https://esm.sh/*solid-js@2.0.0-beta.0&dev/"
14+
}
15+
}
16+
</script>
17+
<script type="module">
18+
import {
19+
availablePresets,
20+
registerPreset,
21+
} from "https://esm.sh/@babel/standalone@7.28.1";
22+
import presetSolid from "https://esm.sh/babel-preset-solid@2.0.0-beta.0";
23+
24+
registerPreset("solid", {
25+
presets: [presetSolid],
26+
});
27+
</script>
28+
<!-- `data-plugins=""` attribute is required for @babel/standalone@7.28.1 -->
29+
<script
30+
type="text/babel"
31+
data-presets="solid,typescript"
32+
data-plugins=""
33+
data-type="module"
34+
src="./main.tsx"
35+
></script>
36+
</head>
37+
<body></body>
38+
</html>

solid-2/main.tsx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/** @jsxImportSource solid-js */
2+
3+
import { render } from "@solidjs/web";
4+
import type { Post } from "jsonplaceholder-types/types/post";
5+
import type { User } from "jsonplaceholder-types/types/user";
6+
import {
7+
createMemo,
8+
createSignal,
9+
For,
10+
isPending,
11+
Loading,
12+
Match,
13+
onCleanup,
14+
Switch,
15+
} from "solid-js";
16+
17+
const urlBase = "https://jsonplaceholder.typicode.com";
18+
19+
async function fetchUsers() {
20+
const ctrl = new AbortController();
21+
onCleanup(() => ctrl.abort());
22+
const response = await fetch(`${urlBase}/users`, { signal: ctrl.signal });
23+
return await response.json() as User[];
24+
}
25+
26+
async function fetchPosts(userId: number) {
27+
const ctrl = new AbortController();
28+
onCleanup(() => ctrl.abort());
29+
const response = await fetch(
30+
`${urlBase}/posts?userId=${userId}`,
31+
{ signal: ctrl.signal },
32+
);
33+
return await response.json() as Post[];
34+
}
35+
36+
function App() {
37+
const [selectedUserId, setSelectedUserId] = createSignal<number>();
38+
const users = createMemo(() => fetchUsers());
39+
const posts = createMemo(() => {
40+
const userId = selectedUserId();
41+
return userId !== undefined ? fetchPosts(userId) : [];
42+
});
43+
44+
return (
45+
<>
46+
<h1>Buildless SolidJS 2 app</h1>
47+
<Loading fallback={<p>Loading Users...</p>}>
48+
<label>
49+
Select User:
50+
<select
51+
onChange={function handleChange(event) {
52+
setSelectedUserId(+event.currentTarget.value);
53+
}}
54+
>
55+
<option hidden selected></option>
56+
<For each={users()}>
57+
{(user) => (
58+
<option value={user().id}>
59+
@{user().username}: {user().name}
60+
</option>
61+
)}
62+
</For>
63+
</select>
64+
</label>
65+
</Loading>
66+
<Switch>
67+
<Match when={selectedUserId() !== undefined}>
68+
<Loading fallback={<p>Loading Posts...</p>}>
69+
<ul>
70+
<For each={posts()}>
71+
{(post) => <li>{post().title}</li>}
72+
</For>
73+
</ul>
74+
</Loading>
75+
</Match>
76+
<Match when={!isPending(users)}>
77+
<p>Select User to view posts</p>
78+
</Match>
79+
</Switch>
80+
<p>
81+
Data Source:
82+
<a href="https://jsonplaceholder.typicode.com/" target="_blank">
83+
JSONPlaceholder
84+
</a>
85+
</p>
86+
</>
87+
);
88+
}
89+
90+
render(() => <App />, document.body);

0 commit comments

Comments
 (0)