Svelte allows conditional rendering based on the value of a variable in component scope. However, if a variable is imported, Svelte will not trigger an update upon the value change.
What is the proper way to trigger an update in this case ?
Example:
App.svelte
<script>
import {flag, setFlag} from './flag.js'
</script>
{#if flag}
<h1>Flag present</h1>
{/if}
<button on:click={e =>setFlag()}>Toggle</button>
flag.js
export let flag = false
export function setFlag() {
flag = true;
}
When clicking the button, the variable in flag.js changes, but the component does not re-render with the new value.