Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Svelte switch/case vs. if logic blocks [closed]

$
0
0

I was wondering whether there are any best practises on when to use a switch/case assignment vs. using if / else if logic blocks in svelte?

E.g. if I have an enum

export enum Status {  riding = "RIDING",  arrived = "ARRIVED",  failed = "FAILED",}

Is it better to use a switch case in the script tag

<script>  let statusText = ""  $: switch (status) {    case Status.riding:      statusText = "Riding"      break    case Status.arrived:      statusText = "Arrived"      break    case Status.failed:      statusText = "Failed"      break  }</script><span class="status-text">  {statusText}</span>

…or to use if / else if logic blocks:

<span class="status-text">  {#if status === Status.riding}"Riding"  {:else if status === Status.arrived}"Arrived"  {:else if status === Status.failed}"Failed"  {/if}</span>

Any recommendation on what to use? Thanks.


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>