-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
coreFeature requests related to core functionalityFeature requests related to core functionality
Description
Maybe we can have useLazyMutation
similar to react-query.
function AddTodo() {
const [addTodo, { data, loading, error }] = useMutation(ADD_TODO);
return (
<div>
<form
onSubmit={(e) => {
e.preventDefault();
// this is a problem because
// button is not disabled because `useMutation loading` is not part of this function
// error thrown will not end up in `useMutation error` so you need to handle it separately
const formData = new FormData(e.target as HTMLFormElement);
if (formData.title.length < 10) {
throw new Error("invalid input");
}
addTodo({ variables: { type: formData.title } });
// would be nice to do something like this instead, similart to react query
addTodo((mutationFn) => {
const formData = new FormData(
e.target as HTMLFormElement,
);
if (formData.title.length < 10) {
throw new Error("invalid input");
}
return mutationFn({
variables: {
type: formData.title,
},
});
});
}}
>
<input name="title" />
<button type="submit" disabled={loading}>
Add Todo
</button>
</form>
</div>
);
}
Metadata
Metadata
Assignees
Labels
coreFeature requests related to core functionalityFeature requests related to core functionality