{"record":{"id":"ec91c3d9d0a29792","repo":"marmelab/react-admin","slug":"usemutationwithmutationmode-mutation-requires-para","errorCode":null,"errorMessage":"useMutationWithMutationMode mutation requires parameters","messagePattern":"useMutationWithMutationMode mutation requires parameters","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/dataProvider/useMutationWithMutationMode.ts","lineNumber":121,"sourceCode":"            UseMutationWithMutationModeOptions<\n                ErrorType,\n                TData,\n                TVariables\n            >['onSettled']\n        >();\n\n    // We don't need to keep a ref on the onSuccess callback as we call it ourselves for optimistic and\n    // undoable mutations. There is a limitation though: if one of the side effects applied by the onSuccess callback\n    // unmounts the component that called the useUpdate hook (redirect for instance), it must be the last one applied,\n    // otherwise the other side effects may not applied.\n    const hasCallTimeOnSuccess = useRef(false);\n\n    const mutation = useMutation<TData['data'], ErrorType, Partial<TVariables>>(\n        {\n            mutationKey,\n            mutationFn: async params => {\n                if (params == null) {\n                    throw new Error(\n                        'useMutationWithMutationMode mutation requires parameters'\n                    );\n                }\n\n                return (\n                    mutateWithMiddlewares\n                        .current(params as TVariables)\n                        // Middlewares expect the data property of the dataProvider response\n                        .then(({ data }) => data)\n                );\n            },\n            ...mutationOptions,\n            onMutate: async (...args) => {\n                if (mutationOptions.onMutate) {\n                    const userContext =\n                        (await mutationOptions.onMutate(...args)) || {};\n                    return {\n                        snapshot: snapshot.current,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/dataProvider/useMutationWithMutationMode.ts#L103-L139","documentation":"Inside useMutationWithMutationMode, the react-query mutation function validates that variables were provided. If the mutate call receives null or undefined variables, the wrapper cannot merge them with its middleware pipeline and throws before invoking the mutationFn.","triggerScenarios":"Calling mutate() or mutate(null) / mutate(undefined) without a variables object; passing a variable that resolves to undefined at call time (e.g. an uninitialized state object).","commonSituations":"Buttons wired to mutate before form state initializes; event handlers calling mutate with an implicit undefined argument; optional-chained values like mutate(formValues?.params) where formValues is null.","solutions":["Always call mutate with a full variables object: mutate({ resource, id, data }).","Guard the handler: if (!params) return; before calling mutate.","Initialize the variables state with a complete default object."],"exampleFix":"// before\nconst { mutate } = useMutationWithMutationMode(...);\nonClick={() => mutate(params)}; // params may be undefined\n// after\nonClick={() => { if (params) mutate(params); }}","handlingStrategy":"validation","validationCode":"if (params == null) {\n  throw new TypeError('mutate requires a variables object');\n}\nmutate(params);","typeGuard":"const isDefined = <T,>(v: T | null | undefined): v is T => v != null;","tryCatchPattern":"try {\n  mutate(params!);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('requires parameters')) {\n    notify('Nothing to submit', { type: 'warning' });\n  } else throw e;\n}","preventionTips":["Never call mutate() with zero arguments.","Initialize variables state with a complete default object.","Guard event handlers against undefined payloads."],"tags":["react-admin","mutation","missing-argument","react-query"],"backgroundTag":"missing-required-argument","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}