diff --git a/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md b/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md index 175b7e3de0..34dcb781e9 100644 --- a/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md +++ b/apps/svelte.dev/src/routes/llms-small.txt/content-svelte.md @@ -294,6 +294,72 @@ let { a, b, ...others } = $props(); - Do **NOT** use this unless you are explicitly tasked to create a custom element using Svelte components +### Using await in Svelte + +- **Where you can use await** + + - **Top-level ` + + +``` + +- Alternative props exist (`loading`, `error`, `current`) if you don’t use `await`. + +### form: mutation via forms + +Define: + +```js +import { form } from '$app/server'; +import * as db from '$lib/server/database'; +import * as auth from '$lib/server/auth'; +import { error, redirect } from '@sveltejs/kit'; + +export const createPost = form(async (data) => { + const user = await auth.getUser(); + if (!user) error(401, 'Unauthorized'); + + const title = data.get('title'); + const content = data.get('content'); + db.insertPost(title, content); + + redirect(303, `/blog/${title}`); +}); +``` + +Use: + +```svelte + + +
+ +