lucia icon indicating copy to clipboard operation
lucia copied to clipboard

Helper function for use:enhance

Open pilcrowonpaper opened this issue 2 years ago • 0 comments

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 })

pilcrowonpaper avatar Oct 15 '22 11:10 pilcrowonpaper