Skip to content

Commit 2cf65ab

Browse files
committed
refactor: use Swtich/Match instead of Show
1 parent 74d6407 commit 2cf65ab

1 file changed

Lines changed: 43 additions & 48 deletions

File tree

solid-1/main.tsx

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/** @jsxImportSource solid-js */
22

3+
import type { Post } from "jsonplaceholder-types/types/post";
4+
import type { User } from "jsonplaceholder-types/types/user";
35
import {
46
type Accessor,
57
createResource,
68
createSignal,
79
For,
10+
Match,
811
onCleanup,
9-
Show,
12+
Switch,
1013
} from "solid-js";
1114
import { render } from "solid-js/web";
12-
import type { User } from "jsonplaceholder-types/types/user";
13-
import type { Post } from "jsonplaceholder-types/types/post";
1415

1516
const urlBase = "https://jsonplaceholder.typicode.com";
1617

@@ -45,52 +46,46 @@ const App = () => {
4546
return (
4647
<>
4748
<h1>Buildless SolidJS 1 app</h1>
48-
<Show
49-
when={users()}
50-
fallback={
51-
<Show when={users.loading}>
52-
<p>Loading Users...</p>
53-
</Show>
54-
}
55-
>
56-
{(users) => (
57-
<label>
58-
Select User:
59-
<select
60-
onChange={(e) => setSelectedUserId(+e.currentTarget.value)}
61-
>
62-
<For each={users()}>
63-
{(user) => (
64-
<option value={user.id}>@{user.username}: {user.name}</option>
65-
)}
49+
<Switch>
50+
<Match when={users()}>
51+
{(users) => (
52+
<label>
53+
Select User:
54+
<select
55+
onChange={(e) => setSelectedUserId(+e.currentTarget.value)}
56+
>
57+
<For each={users()}>
58+
{(user) => (
59+
<option value={user.id}>
60+
@{user.username}: {user.name}
61+
</option>
62+
)}
63+
</For>
64+
</select>
65+
</label>
66+
)}
67+
</Match>
68+
<Match when={users.loading}>
69+
<p>Loading Users...</p>
70+
</Match>
71+
</Switch>
72+
<Switch>
73+
<Match when={posts()}>
74+
{(posts) => (
75+
<ul>
76+
<For each={posts()}>
77+
{(post) => <li>{post.title}</li>}
6678
</For>
67-
</select>
68-
</label>
69-
)}
70-
</Show>
71-
<Show
72-
when={posts()}
73-
fallback={
74-
<Show
75-
when={posts.loading}
76-
fallback={
77-
<Show when={users}>
78-
<p>Select User to view posts</p>
79-
</Show>
80-
}
81-
>
82-
<p>Loading Posts...</p>
83-
</Show>
84-
}
85-
>
86-
{(posts) => (
87-
<ul>
88-
<For each={posts()}>
89-
{(post) => <li>{post.title}</li>}
90-
</For>
91-
</ul>
92-
)}
93-
</Show>
79+
</ul>
80+
)}
81+
</Match>
82+
<Match when={posts.loading}>
83+
<p>Loading Posts...</p>
84+
</Match>
85+
<Match when={users()}>
86+
<p>Select User to view posts</p>
87+
</Match>
88+
</Switch>
9489
<p>
9590
Data Source:
9691
<a href="https://jsonplaceholder.typicode.com/" target="_blank">

0 commit comments

Comments
 (0)