Skip to content

Commit 972e4d8

Browse files
committed
match: Update README to include examples for partial and fallback props
1 parent e071d57 commit 972e4d8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/match/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type MyUnion = {
3636
}
3737

3838
const [value, setValue] = createSignal<MyUnion>({kind: "foo", foo: "foo-value"})
39-
39+
4040
<Match on={value()} case={{
4141
foo: v => <>{v().foo}</>,
4242
bar: v => <>{v().bar}</>,
@@ -62,6 +62,28 @@ type MyUnion = {
6262
}} />
6363
```
6464

65+
### Partial matching
66+
67+
Use the `partial` prop to only handle some of the union members:
68+
69+
```tsx
70+
<Match partial on={value()} case={{
71+
foo: v => <>{v().foo}</>,
72+
// bar case is not handled
73+
}} />
74+
```
75+
76+
### Fallback
77+
78+
Provide a fallback element when no match is found or the value is `null`/`undefined`:
79+
80+
```tsx
81+
<Match on={value()} case={{
82+
foo: v => <>{v().foo}</>,
83+
bar: v => <>{v().bar}</>,
84+
}} fallback={<div>No match found</div>} />
85+
```
86+
6587
## Demo
6688

6789
[Deployed example](https://primitives.solidjs.community/playground/match) | [Source code](https://github.com/solidjs-community/solid-primitives/tree/main/packages/match/dev)

0 commit comments

Comments
 (0)