|
1 | 1 | /** @jsxImportSource solid-js */ |
2 | 2 |
|
| 3 | +import type { Post } from "jsonplaceholder-types/types/post"; |
| 4 | +import type { User } from "jsonplaceholder-types/types/user"; |
3 | 5 | import { |
4 | 6 | type Accessor, |
5 | 7 | createResource, |
6 | 8 | createSignal, |
7 | 9 | For, |
| 10 | + Match, |
8 | 11 | onCleanup, |
9 | | - Show, |
| 12 | + Switch, |
10 | 13 | } from "solid-js"; |
11 | 14 | import { render } from "solid-js/web"; |
12 | | -import type { User } from "jsonplaceholder-types/types/user"; |
13 | | -import type { Post } from "jsonplaceholder-types/types/post"; |
14 | 15 |
|
15 | 16 | const urlBase = "https://jsonplaceholder.typicode.com"; |
16 | 17 |
|
@@ -45,52 +46,46 @@ const App = () => { |
45 | 46 | return ( |
46 | 47 | <> |
47 | 48 | <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>} |
66 | 78 | </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> |
94 | 89 | <p> |
95 | 90 | Data Source: |
96 | 91 | <a href="https://jsonplaceholder.typicode.com/" target="_blank"> |
|
0 commit comments