In Parent.svelte:
<Child {initialName}/>
In Child.svelte
export let initialName;
<p>{initialName}</p>
This works fine, initialName is rendered from value passed from Parent. But I'd like to map it to a reactive variable from store later on ( once the initial comp is rendered).
import {_name} from './store.js';
$: initialName = $_name;
wouldn't work as initialName would be immediately overwritten by value from store. Currently I'm doing below workaround.
let initialized = false;
let l_name;
$: if (true || $_name) {
if (initialized) {
l_name = $_name;
} else {
l_name = initialName;
initialized = true;
}
}
<p>{l_name}</p>
this works, but I find it bit hacky and too much boilerplate. Any other clean way to accomplish the same? One option is to set value directly to store (in Parent comp) and use it <p>$_name</p>. But this had a problem of retaining the old value from store when I refresh the page for a split second.