Skip to content
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

use:enhance shadows data #9845

Closed
Rich-Harris opened this issue May 4, 2023 · 4 comments · Fixed by #9902
Closed

use:enhance shadows data #9845

Rich-Harris opened this issue May 4, 2023 · 4 comments · Fixed by #9902
Labels

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented May 4, 2023

Describe the problem

I want to access the data prop in my use:enhance callback, but I also want to reference the FormData object that was passed in. Right now I have to do ({ data: formData }) => {...} or similar:

<script>
  import { enhance } from '$app/forms';

  export let data;
</script>

<h1>total: {data.total}</h1>

<form
  use:enhance={({ data: formData }) => {
    data.total += +formData.get('n');
  }}
  method="POST"
>
  <input name="n" type="number" />
  <button>add {n}</button>
</form>

Describe the proposed solution

It should probably just be formData in the first place. We can do this non-breakingly (but maybe deprecate data for removal in version 2?)

Alternatives considered

formdata? fd? stuff?

Importance

nice to have

Additional Information

No response

@Rich-Harris
Copy link
Member Author

I suppose form also shadows form, though it's less likely that you'd reference the form prop inside the callback. Hmm

@ghostdevv
Copy link
Member

+1 on formData

@dummdidumm
Copy link
Member

I had to do the same renaming in some other example app before. Which makes me wonder if this is just a good renaming opportunity or if it's a symptom of a bigger problem which is that we want to update data without reloading it, and if there's some opportunity here for enhance to do this somewhat automatically (opt-in).

@gtm-nayan
Copy link
Contributor

gtm-nayan commented May 5, 2023

@dummdidumm That one, I think you're referring to result.data, whereas Rich is talking about the FormData object that the SubmitFunction receives before the request is sent.

Also, it seems the FormData is passed in again to the callback that runs after the submit, but it doesn't appear in the types. Should that be removed or renamed?


And if it is renamed, would it be a breaking change to only keep formData there since it wasn't documented before?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants