I am new to Svelte and there are things I suppose should be easy to do and yet they give me trouble. In a small Svelte app I have this HTML:
<div class="mt-5 mb-6">
<Switch on:click={toggle} /> <span>{stat}</span>
</div>
I need to display "On" or "Off" in the span element, depending on the "state" of the switch. For this purpose, I have:
import Switch from './Switch.svelte';
let stat = 'off';
let status = false;
function toggle () {
status = !status;
stat = status ? "on" : "off";
}
See REPL here.
For a reason I can not understand, even though there's no error in the console, the span always shows "Off". Why?