I am trying to get my head around the svelte 3 reactivity thing...
I wanted to force refreshing a UI on a button click. I am using a custom component
AsyncFetcher
that accepts HTTP post data, and returnsdata
object (http post result) for its slot.I wanted to have a disable functionality. So when the "Disable" button is clicked an http api is called followed by a refresh of the data view.
<script>
export let id
function onDisable() {
fetch('disable-api-url', {id: id})
// Then ??
// What to do after the fetch call, to refresh the view
}
</script>
<AsyncFetcher postParam={id} let:data>
{data.name}
<button on:click={??}>Refresh</button>
<button on:click={onDisable}>Disable Item</button>
</AsyncFetcher>
I tried doing on:click={() => id=id}
to trick it to refresh to no avail. If id
would have been an object rather than string id={...id}
would have worked, which unfortunately, is not the case here.
What would be a correct way to achieve this?