wervt
API

useShape

Live rows of a shape, rendered on the server.
<script setup lang="ts">
const { data, isLive, error } = await useShape<Todo>('/api/shapes/todos')
</script>

Auto-imported by the module.

Parameters

Type
pathstringA route that serves a shape with proxyShape.
options.keystringPayload key, defaults to the path.
options.livebooleanKeep the rows live on the client. Default true.

Returns

Type
dataShallowRef<T[]>Current rows, in no particular order. Sort with computed.
isLiveRef<boolean>true once the client stream is up to date.
errorRef<unknown>Loading or streaming error.

Behaviour

  • Server: loads the shape snapshot through the route in-process (cookies and authorization are forwarded) and stores rows, offset and shape handle in the payload.
  • Client: starts an Electric ShapeStream from the stored offset on mount and applies inserts, updates (merged into the existing row) and deletes. A must-refetch from Electric clears the rows and reloads.
  • On client-side navigation without SSR, the snapshot is loaded in the browser first.
Copyright © 2026