Documentation Index
Fetch the complete documentation index at: https://docs.modelence.com/llms.txt
Use this file to discover all available pages before exploring further.
API Reference / @modelence/react-query / modelenceMutation
modelenceMutation<T>(methodName, defaultArgs): object
Defined in: index.ts:242
Creates mutation options for use with TanStack Query’s useMutation hook.
Example
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { modelenceMutation } from '@modelence/react-query';
function MyComponent() {
const queryClient = useQueryClient();
// Basic usage
const { mutate } = useMutation(modelenceMutation('todos.create'));
// With additional options
const { mutate: updateTodo } = useMutation({
...modelenceMutation('todos.update'),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['todos.getAll'] });
},
});
return <button onClick={() => mutate({ title: 'New Todo' })}>Create</button>;
}
Type Parameters
| Type Parameter | Default type | Description |
|---|
T | unknown | The expected return type of the mutation |
Parameters
| Parameter | Type | Description |
|---|
methodName | string | The name of the method to mutate |
defaultArgs | Args | Optional default arguments to merge with mutation variables |
Returns
object
Mutation options object for TanStack Query’s useMutation
| Name | Type | Defined in |
|---|
mutationFn() | (variables) => Promise<T> | index.ts:247 |