return memoized value
See original GitHub issuecurrently returned value both of useMutation and useQuery calculated every time they called, I’m not really familiar with apollo logics, but I guess this can memoized?, for instance useMutation should be similar like this:
export function useMutation(mutation, baseOptions) {
const previousOptions = useRef();
const client = useApolloClient();
const result = isEqual(previousOptions.current, baseOptions);
return useMemo(
() => {
previousOptions.current = baseOptions;
return localOptions => client.mutate({
mutation,
...baseOptions,
...localOptions,
});
},
[
mutation,
result ? previousOptions.current : baseOptions,
],
);
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How to Memoize Functions and Values in JavaScript and React
Unlike the useMemo() hook that memoizes only the returned value of a function, React.memo memoizes the whole function. Use React.memo only for ...
Read more >Memoization in React js - Topcoder
In React, the memo is the higher-order component in short HOC (HOC are functions that take a component and return a new component)....
Read more >What is Memoization? How and When to ... - freeCodeCamp
With memoization, there's no need to recalculate the same values once and again – we just store each computation and return the same...
Read more >What is Memoization in React? | Syncfusion Blogs
Memoization is an optimization technique for accelerating computer programs by caching the results of heavy function calls and returning ...
Read more >How to Implement Memoization in React to Improve ... - SitePoint
In this tutorial, we'll learn how to implement memoization in React. Memoization improves performance by storing the results of expensive ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

no, I did not, but I guess with memorized version you can actually prevent re-rendering e.g:
with current implimention
mutatealways have a new value therefore it might re-render more…Checking for
mutationitself is not enough, we have to check for changes ofoptionsparameters, and this will create unnecessary memoization most of the times.Anyways, React team does not suggest to pass individual callbacks in props and there is (not ideal) solution for this. I hope they will come up with better idea.
But if you don’t like it, you still can use your own hook for memoization , e.g: