UNPKG

1.83 kBTypeScriptView Raw
1import type { DocumentNode } from "graphql";
2import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
3import type { MutationHookOptions, MutationTuple, NoInfer } from "../types/types.js";
4import type { ApolloCache, DefaultContext, OperationVariables } from "../../core/index.js";
5/**
6 *
7 *
8 * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
9 *
10 * @example
11 * ```jsx
12 * import { gql, useMutation } from '@apollo/client';
13 *
14 * const ADD_TODO = gql`
15 * mutation AddTodo($type: String!) {
16 * addTodo(type: $type) {
17 * id
18 * type
19 * }
20 * }
21 * `;
22 *
23 * function AddTodo() {
24 * let input;
25 * const [addTodo, { data }] = useMutation(ADD_TODO);
26 *
27 * return (
28 * <div>
29 * <form
30 * onSubmit={e => {
31 * e.preventDefault();
32 * addTodo({ variables: { type: input.value } });
33 * input.value = '';
34 * }}
35 * >
36 * <input
37 * ref={node => {
38 * input = node;
39 * }}
40 * />
41 * <button type="submit">Add Todo</button>
42 * </form>
43 * </div>
44 * );
45 * }
46 * ```
47 * @since 3.0.0
48 * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
49 * @param options - Options to control how the mutation is executed.
50 * @returns A tuple in the form of `[mutate, result]`
51 */
52export declare function useMutation<TData = any, TVariables = OperationVariables, TContext = DefaultContext, TCache extends ApolloCache<any> = ApolloCache<any>>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: MutationHookOptions<NoInfer<TData>, NoInfer<TVariables>, TContext, TCache>): MutationTuple<TData, TVariables, TContext, TCache>;
53//# sourceMappingURL=useMutation.d.ts.map
\No newline at end of file