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

Allow passing params and queries (ZodiosRequestOptions) to mutate() #252

Open
lnogol opened this issue Feb 18, 2023 · 6 comments
Open

Allow passing params and queries (ZodiosRequestOptions) to mutate() #252

lnogol opened this issue Feb 18, 2023 · 6 comments

Comments

@lnogol
Copy link

lnogol commented Feb 18, 2023

currently hooks.use[Alias] (and other mutation hooks) require passing params and queries to the hook call

it would be nice to be able to pass that to .mutate() instead, for cases where a param or query is not held in state / not known during the hook call

@robotkutya
Copy link

This would be important. A common use case:

  1. you fetch an array of data
  2. you build a list from the array
  3. each list item has an event handler that you have to pass a mutate onto

If your hooks.use[Alias] function is dependent on the fetched data, you are in trouble, because you can't instantiate the const { mutate } = hooks.use[Alias] mutation inside the event handler, without getting an error "Hooks can only be called inside the body of a function component."

With vanilla react-query, you can do this by providing a mutationFn for the useMutation hook that has the params coming from the data, and you can call the mutation function inside event handlers.

@hanayashiki
Copy link

hanayashiki commented Apr 5, 2023

Any updates on this?

Without breaking the current API, I might suggest passing optional queries and path params to the second parameter of mutate/mutateAsync, and make it required if any of those parameters are not passed in the use hook.

const { mutateAsync } = hooks.usePost('/book/:id');

const onClick = () => {
  await mutateAsync({ ...body }, { queries: { action: '...' }, params: { id: '... } });  
} 

@ecyrbe
Copy link
Owner

ecyrbe commented Apr 5, 2023

This will be available on v11 as it's a breaking change

@markkkkas
Copy link

Hey any updates on this?

@ecyrbe
Copy link
Owner

ecyrbe commented Jun 2, 2023

I'm waiting for tanstack query v5 before releasing v11, else this would be Bad to release another breaking change soon after.

@briandiephuis
Copy link

https:/TanStack/query/releases/tag/v5.0.0-rc.1 just came out, would be really nice to have this feature 😊

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

6 participants