<Switch> / <Match>
Edit this pageUseful for when there are more than 2 mutual exclusive conditions. It is a more flexible version of the if-else-if-else-if-else-... chain.
A super simple implementation of this component would be:
For example, it can be used to perform basic routing:
Match also supports function children to serve as keyed flow.
Props
Switch
Name | Type | Default | Description |
---|---|---|---|
fallback | JSX.Element | undefined | The fallback element to render if no Match component has a truthy when prop. |
Match
Name | Type | Default | Description |
---|---|---|---|
when | T | undefined | null | false | undefined | The condition to check. If it is truthy, the children will be rendered. |