useSuspenseView function

Module @runic-artifex/svelte in @runic-artifex/svelte 0.23.0

function useSuspenseView<TClient extends ViewClient>(source: ViewConnector<TClient> | TClient, options?: UseViewOptions<TClient>): Promise<SuspenseViewHandle<TClient>>;

Connects a generated View reference while the calling component is mounted, like useView, and returns a promise that resolves once it connected, with reactive state and client that are never undefined, or rejects with the connection failure. Call it during component initialization and await it in the markup:

<script lang="ts">
  let { page }: { page: CounterPageReference } = $props();
  const counter = useSuspenseView(page);
</script>

{#await counter}
  <p>Connecting…</p>
{:then view}
  <button onclick={() => view.client.increment()}>{view.state.count}</button>
{:catch error}
  <p role="alert">{describeBridgeError(error)}</p>
{/await}

The source is read once; key the component ({#key page}) to follow another reference. A reference whose client another component let go of within its keepAlive period resolves at once.