Type Parameters
- TPath extends string
- TData = any
- TFormData = OnlyObject
- TExtraData = any
Returns {
create: ((__namedParameters: CreateOneVariables<TPath, TFormData, TExtraData>) => void);
mutation:
| {
context: unknown;
data: undefined;
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: true;
isPaused: boolean;
isPending: false;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "idle";
submittedAt: number;
variables: undefined;
}
| {
context: unknown;
data: undefined;
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: false;
isPaused: boolean;
isPending: true;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "pending";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
}
| {
context: unknown;
data: undefined;
error: CustomError;
failureCount: number;
failureReason: null | CustomError;
isError: true;
isIdle: false;
isPaused: boolean;
isPending: false;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "error";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
}
| {
context: unknown;
data: QueryResponse<TData> | QueryResponse<TData>[];
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: false;
isPaused: boolean;
isPending: false;
isSuccess: true;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "success";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
};
}
An object with a single properties, create
and mutation
.
create
is a function that takes the data and params of the resource to create,
and calls the mutation function with the data and the resource.
mutation
is result useMutation
without propery mutate
- (__namedParameters): void
Returns void
mutation:
| {
context: unknown;
data: undefined;
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: true;
isPaused: boolean;
isPending: false;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "idle";
submittedAt: number;
variables: undefined;
}
| {
context: unknown;
data: undefined;
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: false;
isPaused: boolean;
isPending: true;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "pending";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
}
| {
context: unknown;
data: undefined;
error: CustomError;
failureCount: number;
failureReason: null | CustomError;
isError: true;
isIdle: false;
isPaused: boolean;
isPending: false;
isSuccess: false;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "error";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
}
| {
context: unknown;
data: QueryResponse<TData> | QueryResponse<TData>[];
error: null;
failureCount: number;
failureReason: null | CustomError;
isError: false;
isIdle: false;
isPaused: boolean;
isPending: false;
isSuccess: true;
mutateAsync: UseMutateAsyncFunction<QueryResponse<TData> | QueryResponse<TData>[], CustomError, MutateVariables<TPath, TFormData, TExtraData>, unknown>;
reset: (() => void);
status: "success";
submittedAt: number;
variables: MutateVariables<TPath, TFormData, TExtraData>;
}
A hook that helps you create a new resource.
The hook uses
useMutation
from@tanstack/react-query
under the hood, so it accepts all the same options.The hook returns an object with a single property,
create
, which is a function that takes the data and params of the resource to create, and calls the mutation function with the data and the resource.The hook also sets the query data for the created resource and invalidates the list of resources, so that the list is refetched when the mutation is successful.
Example