Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid un-necessary
useMutation
re-renders
apollographql/react-apollo#3417 adjusted `useMutation` to make sure the current `ApolloClient` instance is available in the result returned when `useMutation` is first called. Unfortunately, the changes in that PR are unintentionally modifying the `useState` based `result` object directly, instead of using `setResult`. This is ultimately leading to inconsistencies around the `client` instance sometimes being included in the result and stored as the `previousResult`, and other times not being included. This can then lead to infinite loop / too many render problems caused by the `!equal(this.previousResult, result)` check in `updateResult` always passing, and the state continuously being updated by repeated calls to `setResult`. This commit adjusts the returned `useMutation` result to be a copy of the original `useState` based `result`, which then includes the `client` instance. This ensures the `useState` controlled `result` object is not mutated outside of calling `setResult`, and avoids the infinite loop / too many render issue.
- Loading branch information