Convex is the typesafe backend-as-a-service with realtime updates, server functions, crons and scheduled jobs, file storage, vector search, and more.
Receive live updates to Convex query subscriptions and call mutations and actions from Svelte with convex-svelte.
Full documentation lives at docs.convex.dev/client/svelte/overview:
- Reactivity — queries, mutations & actions, client access, and paginated queries.
- SvelteKit Server Rendering — SSR with
convexLoad/convexLoadPaginated, theinitialDataalternative, server helpers, and deploying. - Authentication — wiring an auth provider with
setupAuth/useAuth. - Troubleshooting — common issues and fixes.
npm install convex convex-svelteSvelte doesn't like referencing code outside of src/, so customize the Convex functions directory by creating a convex.json in your project root:
{
"functions": "src/convex/"
}Then set up a Convex dev deployment:
npx convex devCall setupConvex() once in your root layout, then subscribe to queries with useQuery() in any component:
<!-- +layout.svelte -->
<script lang="ts">
import { setupConvex } from 'convex-svelte';
import { PUBLIC_CONVEX_URL } from '$env/static/public';
setupConvex(PUBLIC_CONVEX_URL);
</script><script lang="ts">
import { useQuery } from 'convex-svelte';
import { api } from '../convex/_generated/api.js';
const messages = useQuery(api.messages.list, {});
</script>
{#if messages.isLoading}
Loading...
{:else if messages.error}
Failed to load: {messages.error.toString()}
{:else}
{#each messages.data as message}
<p>{message.author}: {message.body}</p>
{/each}
{/if}See the Quickstart and the full documentation for more.