-
Hi! I have a mutation which I wants to trigger when the component mount. Since I am using const myMutation = useMutation({...});
useEffect(() => {
myMutation.mutate();
}, []);
So I thought about this as a solution: const isMutationHasRun = useRef(false);
const myMutation = useMutation({...});
useEffect(() => {
if (!isMutationHasRun.current) {
isMutationHasRun.current = true;
myMutation.mutate();
}
}, []); This is works as expected and triggers the mutation only once. However, when I am using Do you have any suggestion how to overcome this issue (without removing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So I found this discussion which basically the same as the one that I opened. |
Beta Was this translation helpful? Give feedback.
So I found this discussion which basically the same as the one that I opened.
I think that @TkDodo comment explains it pretty well.