#does useMutation have a loading state?
2 messages · Page 1 of 1 (latest)
The Convex React useMutation hook itself does not directly provide a loading state (such as isLoading) in its return value. Instead, it returns a function you can call to execute the mutation, and you can handle loading state in your component logic by tracking when the mutation is in progress (for example, by setting your own state before and after calling the mutation function) Editing data.
For example:
const doSomething = useMutation(api.functions.doSomething);
const [loading, setLoading] = useState(false);
const onClick = async () => {
setLoading(true);
try {
await doSomething();
} finally {
setLoading(false);
}
};
If you are using Convex with TanStack Query, their useMutation hook does provide an isPending state, but this is part of TanStack Query, not Convex's own useMutation Mutations (TanStack).