T
TanStack•3y ago
stormy-gold

Referential stability of the mutation object

The useMutation hook consistently returns properties with stable references, however, the hook itself produces a new object with each use. As a result, directly including the entire mutation object in dependency arrays can be problematic. Is this design a deliberate prompt to encourage developers to only add the specific properties they require to their dependency arrays (thus adhering to best practices)?
2 Replies
vicious-gold
vicious-gold•3y ago
it's kinda both 😅. I think we lost referential stability when refactoring to adhere to concurrent mode requirements a while back, but on a similar note, I recently learned that the array you get back from useState is also a new reference on every render
stormy-gold
stormy-goldOP•3y ago
Curious if there would be interest in updating the documentation to recommend destructing the mutation object as a standard practice—similar to the documentation for React when using useState. I would be happy to make a pull request with the changes.

Did you find this page helpful?