mutate
not clearing errors
#2491
Replies: 3 comments 1 reply
-
Another workaround is to use the new import React from "react";
import useSWRMutation from "swr/mutation";
export default function ModalContent() {
const { trigger, isMutating, error, reset } = useSWRMutation(
"/api/foo",
() => {
throw new Error("Something went wrong");
}
);
React.useEffect(() => {
// This resets any error state from a previous useSWRMutation call
reset();
}, [reset]);
return (
<>
<button disabled={isMutating} onClick={async () => await trigger()}>
Create Something
</button>
{error && <span>{error.message}</span>}
</>
);
} |
Beta Was this translation helpful? Give feedback.
-
I'm wondering why the issue was moved to discussions? I think undocumented change how errors are cleared at version |
Beta Was this translation helpful? Give feedback.
-
I ran into this bug as well and don't quite understand why this is expected behavior. In my case I was doing the following:
I fixed this by calling |
Beta Was this translation helpful? Give feedback.
-
Bug report
Description / Observed Behavior
Calling
mutate
is not clearing errors when using[email protected]
or newer. Prior to that version (e.g., in2.0.0-beta.6
) erros are cleared properly when callingmutate
.Expected Behavior
I expect SWR to clear errors when calling mutate as it was doing previously. E.g., when clearing cache errors should be cleared with data:
Repro Steps / Code Example
[email protected]
)[email protected]
).swr
version is the only difference between the two.Additional Context
Currently when using
[email protected]
all errors can be cleared with a following workaround:Beta Was this translation helpful? Give feedback.
All reactions