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

useMutation should assume input is required #2

Closed
paul-sachs opened this issue Dec 13, 2022 · 1 comment
Closed

useMutation should assume input is required #2

paul-sachs opened this issue Dec 13, 2022 · 1 comment

Comments

@paul-sachs
Copy link
Collaborator

The following example currently throws a typescript error:

const deleteOrg = useMutation({
  ...deleteOrganizationByName.useMutation(),
  onSuccess: (_, { name }) => {
    showToast(`Successfully deleted organization "${name ?? ""}"`);
  },
}); 

Because it's assumed params is optional. We can work around this via something like:

const deleteOrg = useMutation({
  ...deleteOrganizationByName.useMutation(),
  onSuccess: (_, input) => {
    if (input === undefined) {
      return;
    }
    const { name } = input;
    showToast(`Successfully deleted organization "${name ?? ""}"`);
  },
}); 

But given that most mutation should have some kind of input, this feels unnecessary. We already have to default name to "" because we can't assume validation but that's a larger protobuf-es thing to tackle.

@paul-sachs
Copy link
Collaborator Author

In retrospect, this is fine. There are certainly cases where a mutations might not have parameters, and currently protobuf objects default to all properties being optional.

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

No branches or pull requests

1 participant