Skip to content

How to correctly set response for actions #12725

Answered by brunnerh
KarChung-Konstant asked this question in Q&A
Discussion options

You must be logged in to vote

The data is serialized using devalue, which is a more powerful serializer than the built-in one.

Form actions are meant to be used with forms, which will work even if JS fails to load. They can be progressively enhanced so no additional page reload is required if JS loaded. The enhance action can also be used to attach additional logic to the form submission. I would recommend using this.

If you need to use the action directly regardless, SvelteKit provides a function you can use to deserialize the data.

import { deserialize } from '$app/forms';
const result: ActionResult = deserialize(await response.text());

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by KarChung-Konstant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants