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

useMultiMutation() mutation on list views #88

Open
posva opened this issue Oct 14, 2024 · 2 comments
Open

useMultiMutation() mutation on list views #88

posva opened this issue Oct 14, 2024 · 2 comments
Labels
💬 discussion topic that requires further discussion ✨ feature request a new feature request

Comments

@posva
Copy link
Owner

posva commented Oct 14, 2024

When using a regular useMutation() within a list view, you can mutate different entities but you only get access to the loading state of the last one. It would be useful to allow a version that requires a key to compute the different properties in a Map and then each value becomes a function instead of a computed: data(key), isLoading(key) so we can check the progress

Problems:

  • How long should each data be preserved
  • Should there be a way to remove the data
  • Any difference between errors and successes?
@posva posva converted this from a draft issue Oct 14, 2024
@posva posva added ✨ feature request a new feature request 💬 discussion topic that requires further discussion labels Oct 14, 2024
@tsiotska
Copy link

tsiotska commented Dec 2, 2024

@posva Is this desired usage example?

 const { data, isLoading, error, mutate, reset, clearKey } = useMultiMutation({
   mutation: async (id: number) => {
     return await api.deleteItem(id)
   },
    onSuccess: () => {
     console.log('Last mutation succeeded')
   },
   onError: () => {
      console.log('Last mutation failed')
   },
 })
 
 mutate('item-1')
 
  if (isLoading('item-1')) {
  console.log('Loading...')
 }
 
 console.log(data('item-1'))
 console.log(error('item-1'))
 
 reset('item-1')
 clearKey('item-1')

Copy link
Owner Author

posva commented Dec 3, 2024

Yes, more or less. It should have a required key I think but it's indeed really nice to have it based on parameters when they are serializable. Maybe here the key should allow a plain value return instead of forcing an array. What is the purpose of clearKey()? I think having reset() is enough

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 discussion topic that requires further discussion ✨ feature request a new feature request
Projects
Status: Todo
Development

No branches or pull requests

2 participants