lucia
lucia copied to clipboard
Helper function for use:enhance
Right now forms look like this:
<form
method="post"
use:enhance={() => {
return async ({ result }) => {
if (result.type === 'redirect') {
window.location.href = result.location;
return;
}
applyAction(result); // default user:enhance behavior
};
}}
>
</form>
This is a lot to write, and it's such a common use case that I think it's worth providing a function that handles use:enhance
. I'm thinking something like this:
<form
method="post"
use:enhance={handleFormSubmission()}
>
</form>
handleFormSubmission()
can take an optional param:
handleFormSubmission({ onSubmit, onResponse })