Skip to content

Attempt to clarify use:enhance docs #13819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions documentation/docs/20-core-concepts/30-form-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ Without an argument, `use:enhance` will emulate the browser-native behaviour, ju

### Customising use:enhance

To customise the behaviour, you can provide a `SubmitFunction` that runs immediately before the form is submitted, and (optionally) returns a callback that runs with the `ActionResult`. Note that if you return a callback, the default behavior mentioned above is not triggered. To get it back, call `update`.
To customise the behaviour, you can provide a `SubmitFunction` that runs immediately before the form is submitted, and (optionally) returns a callback that runs with the `ActionResult`.

```svelte
<form
Expand All @@ -390,7 +390,7 @@ To customise the behaviour, you can provide a `SubmitFunction` that runs immedia

You can use these functions to show and hide loading UI, and so on.

If you return a callback, you may need to reproduce part of the default `use:enhance` behaviour, but without invalidating all data on a successful response. You can do so with `applyAction`:
Note that if you return a callback, the default behavior mentioned above is not triggered. The simplest way to get it back is to call `update`. You can customize it by passing `reset: false` and/or `invalidateAll: false` to `update`, or customize it even more by manually reproducing parts of the `use:enhance` behavior with `applyAction`:

```svelte
/// file: src/routes/login/+page.svelte
Expand Down
Loading