File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ type MyUnion = {
3636}
3737
3838const [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 )
You can’t perform that action at this time.
0 commit comments