Update to simplify and DRY the code even more.

Instead of replicating the entire button, you could just IF/ELSE the button text.
pull/3673/head
Bryan Klein 6 years ago committed by GitHub
parent def776520f
commit 5bafef27b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,15 +5,13 @@ title: Else blocks
Since the two conditions — `if user.loggedIn` and `if !user.loggedIn` — are mutually exclusive, we can simplify this component slightly by using an `else` block:
```html
{#if user.loggedIn}
<button on:click={toggle}>
<button on:click={toggle}>
{#if user.loggedIn}
Log out
</button>
{:else}
<button on:click={toggle}>
{:else}
Log in
</button>
{/if}
{/if}
</button>
```
> A `#` character always indicates a *block opening* tag. A `/` character always indicates a *block closing* tag. A `:` character, as in `{:else}`, indicates a *block continuation* tag. Don't worry — you've already learned almost all the syntax Svelte adds to HTML.
Loading…
Cancel
Save