Skip to content

Commit b94ffde

Browse files
committed
update
1 parent 4d7eb35 commit b94ffde

1 file changed

Lines changed: 15 additions & 22 deletions

File tree

src/routes/reference/components/switch-and-match.mdx

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,45 +77,38 @@ Controls whether function children receive the current value directly instead of
7777

7878
### `children`
7979

80-
- **Type:** `JSX.Element | ((item) => JSX.Element)`
80+
- **Type:** `JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element) | ((item: NonNullable<T>) => JSX.Element)`
8181

82-
Content rendered when the branch matches. Function children receive an accessor or value based on `keyed`.
82+
Content rendered when the branch matches.
8383

8484
## Return value
8585

8686
- **Type:** `JSX.Element`
8787

88+
Returns the selected branch or the `fallback` content.
89+
8890
## Behavior
8991

90-
- `<Switch>` evaluates its child `<Match>` elements in order and renders the first truthy branch.
92+
- `<Switch>` evaluates its child `<Match>` elements in order and renders only the first truthy branch.
9193
- If no branch matches, `<Switch>` renders `fallback`.
92-
- Function children in `<Match>` follow the same keyed behavior as [`<Show>`](/reference/components/show): with `keyed={false}`, they receive an accessor; with `keyed={true}`, they receive the value directly.
94+
- With `keyed={false}`, function children in `<Match>` receive an accessor that can only be read while that branch remains selected. With `keyed={true}`, they receive the value directly.
9395

9496
## Examples
9597

9698
### Basic usage
9799

98100
```tsx
99-
import { Match, Switch } from "solid-js";
100-
101-
<Switch fallback={<div>Not Found</div>}>
102-
<Match when={state.route === "home"}>
103-
<Home />
101+
<Switch fallback={<p>Unknown status</p>}>
102+
<Match when={state.status === "loading"}>
103+
<p>Loading...</p>
104104
</Match>
105-
<Match when={state.route === "settings"}>
106-
<Settings />
105+
<Match when={state.status === "success"}>
106+
<p>Saved</p>
107107
</Match>
108-
</Switch>;
109-
```
110-
111-
### Function child
112-
113-
```tsx
114-
import { Match, Switch } from "solid-js";
115-
116-
<Switch>
117-
<Match when={user()}>{(user) => <div>{user().name}</div>}</Match>
118-
</Switch>;
108+
<Match when={state.status === "error"}>
109+
<p>Failed</p>
110+
</Match>
111+
</Switch>
119112
```
120113

121114
## Related

0 commit comments

Comments
 (0)