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

Don't pass useMutation result to dep arrays #2367

Closed
david-crespo opened this issue Aug 13, 2024 · 1 comment
Closed

Don't pass useMutation result to dep arrays #2367

david-crespo opened this issue Aug 13, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@david-crespo
Copy link
Collaborator

david-crespo commented Aug 13, 2024

As I learned in #2360 (comment), the object returned by useMutation is not referentially stable — it is remade on every render. But I thought it was, so we're using it in a lot of dependency arrays. We basically need to go through every useApiMutation call and check if the mutation is being included in a dependency array, and change it to depend directly on the relevant property instead, like the mutate function (which is stable). Unfortunately I can't think of a way to lint this, so we'll just have to try to do it as goodly as we can.

const deleteImage = useApiMutation('imageDelete', {
onSuccess(_data, variables) {
addToast({ content: `${variables.path.image} has been deleted` })
queryClient.invalidateQueries('imageList')
},
})
const makeActions = useCallback(
(image: Image): MenuAction[] => [
{
label: 'Demote',
onActivate: () => setDemoteImage(image),
},
{
label: 'Delete',
onActivate: confirmDelete({
doDelete: () => deleteImage.mutateAsync({ path: { image: image.name } }),
label: image.name,
}),
},
],
[deleteImage]
)

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

No branches or pull requests

2 participants