Skip to content

Commit 8be2d57

Browse files
committed
fix: Update README and add example for using tag
1 parent 96adc34 commit 8be2d57

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

packages/match/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,40 @@ Control-flow component for matching discriminated union (tagged union) members.
2828

2929
```tsx
3030
type MyUnion = {
31-
kind: 'foo',
32-
foo: 'foo-value',
31+
kind: "foo",
32+
foo: "foo-value",
3333
} | {
34-
kind: 'bar',
35-
bar: 'bar-value',
34+
kind: "bar",
35+
bar: "bar-value",
3636
}
3737

38-
const [value, setValue] = s.createSignal<MyUnion>({kind: 'foo', foo: 'foo-value'})
38+
const [value, setValue] = createSignal<MyUnion>({kind: "foo", foo: "foo-value"})
3939

4040
<Match on={value()} case={{
4141
foo: v => <>{v().foo}</>,
4242
bar: v => <>{v().bar}</>,
4343
}} />
4444
```
4545

46+
### Changing the tag key
47+
48+
The default tag key is `"kind"`, but it can be changed with the `tag` prop:
49+
50+
```tsx
51+
type MyUnion = {
52+
type: "foo",
53+
foo: "foo-value",
54+
} | {
55+
type: "bar",
56+
bar: "bar-value",
57+
}
58+
59+
<Match on={value()} tag="type" case={{
60+
foo: v => <>{v().foo}</>,
61+
bar: v => <>{v().bar}</>,
62+
}} />
63+
```
64+
4665
## Demo
4766

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

packages/match/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { type Accessor, type JSX, createMemo } from "solid-js"
1313
* bar: 'bar-value',
1414
* }
1515
*
16-
* const [value, setValue] = s.createSignal<MyUnion>({kind: 'foo', foo: 'foo-value'})
16+
* const [value, setValue] = createSignal<MyUnion>({kind: 'foo', foo: 'foo-value'})
1717
*
1818
* <Match on={value()} case={{
1919
* foo: v => <>{v().foo}</>,

0 commit comments

Comments
 (0)