In anticipation of the release of Svelte 5, Triplit's Svelte bindings use runes (opens in a new tab). You must be using one of the pre-release versions of Svelte 5. You can force the compiler into "runes mode" like this (opens in a new tab).

If you are using Svelte, you can use the hooks provided by @triplit/svelte:

npm i @triplit/svelte


If you are using SvelteKit, you can use the hooks described below, but you will need to ensure that the client only attempts to connect to the sync server over WebSockets when in the browser. You can do this by checking if the browser variable from $app/environment is true.

import { TriplitClient } from '@triplit/client';
import { browser } from '$app/environment';
import { PUBLIC_TRIPLIT_URL, PUBLIC_TRIPLIT_TOKEN } from '$env/static/public';
export const client = new TriplitClient({
  autoConnect: browser,

The suggested pattern is to create a client instance in a module and import it into your components.


The useQuery hook subscribes to the provided query inside your Svelte component and will automatically unsubscribe from the query when the component unmounts.

The result of the hook is an object with the following properties:

  • results: A Map containing the results of the query, with entity ids as keys and entities as values.
  • fetching: A boolean indicating whether the query is currently fetching.
  • fetchingRemote: A boolean indicating whether the query is currently fetching from the server.
  • error: An error object if the query failed to fetch.
<script lang="ts">
  import { useQuery } from '@triplit/svelte'
  import { TriplitClient } from '@triplit/client'
  import { schema } from '../triplit/schema';
  const client = new TriplitClient({ schema });
  let data = useQuery(client, client.query('todos'));
  let todosArray = $derived(data.results ? Array.from(data.results): [])
  {#if data.fetching}
  {:else if data.error}
    <p>Error: {data.error.message}</p>
      {#each todosArray as [_id, todo]}


The useConnectionStatus hook subscribes to changes to the connection status of the client and will automatically unsubscribe when the component unmounts.

<script lang='ts'>
  import { useConnectionStatus } from '@triplit/svelte';
  import { TriplitClient } from '@triplit/client'
  const client = new TriplitClient({
    serverUrl: import.meta.env.VITE_TRIPLIT_SERVER_URL,
    token: import.meta.env.VITE_TRIPLIT_TOKEN,
  const connection = useConnectionStatus(client);
{#if connection.status === 'OPEN'}
  <p>The client is connected</p>
  <p>The client is not connected</p>