The example below has two files: index.svelte is hosted in the slot provided in __layout.svelte. When you click the button it should change the color of the box in the hosted page. The code below works fine if index.svelte is a child component, but does not work if index.svelte is a page hosted in the slot. I am sure this is because props work differently with hosted pages.
I have tried using setContext/getContext and a writable store to pass the information across, but I have not found a way to make this reactive so that the box color change takes effect immediately - everything I have tried requires reloading index.svelte to apply the color change.
Is there a reactive way to update elements on the hosted page immediately?
__layout.svelte:
<script>
let color = "green";
function onClick(e) {
color = "red";
}
</script>
<button on:click={onClick}>Red</button>
<slot color={color}></slot>
index.svelte:
<script>
export let color = "blue";
</script>
<div class="box" style="background-color:{color}"></div>
<style>
.box {
width: 100px;
height: 100px;
margin: 10px;
}
</style>
Code above can be found here: