('pessimistic');
+ const [updateMany, { isPending }] = useUpdateMany(
+ 'posts',
+ {
+ ids: [1, 2],
+ data: { id: undefined, title: 'world' },
+ },
+ { mutationMode }
+ );
+ const handleClick = () => {
+ updateMany();
+ };
+ return (
+ <>
+ {JSON.stringify(data)}
+
+
+
+
+
+ >
+ );
+};
+
+export const Params = ({ dataProvider }: { dataProvider?: DataProvider }) => {
+ const data = [
+ { id: 1, title: 'foo' },
+ { id: 2, title: 'bar' },
+ ];
+ const defaultDataProvider = {
+ getList: async () => ({ data, total: 2 }),
+ updateMany: () => new Promise(() => {}), // never resolve to see only optimistic update
+ } as any;
+ return (
+
+
+
+ );
+};
+
+const ParamsCore = () => {
+ const { data } = useGetList('posts');
+ const [params, setParams] = React.useState({});
+ const [updateMany, { isPending }] = useUpdateMany(
+ 'posts',
+ {
+ ids: [1, 2],
+ data: { id: undefined, title: 'world' },
+ meta: params.meta,
+ },
+ { mutationMode: 'optimistic' }
+ );
+ const handleClick = () => {
+ updateMany();
+ };
+ return (
+ <>
+ {JSON.stringify(data)}
+
+
+
+
+
+ >
+ );
+};
diff --git a/packages/ra-core/src/dataProvider/useUpdateMany.ts b/packages/ra-core/src/dataProvider/useUpdateMany.ts
index 1f261467d25..0051e37fbc0 100644
--- a/packages/ra-core/src/dataProvider/useUpdateMany.ts
+++ b/packages/ra-core/src/dataProvider/useUpdateMany.ts
@@ -1,4 +1,4 @@
-import { useMemo, useRef } from 'react';
+import { useEffect, useMemo, useRef } from 'react';
import {
useMutation,
useQueryClient,
@@ -95,9 +95,18 @@ export const useUpdateMany = <
getMutateWithMiddlewares,
...mutationOptions
} = options;
+
const mode = useRef(mutationMode);
+ useEffect(() => {
+ mode.current = mutationMode;
+ }, [mutationMode]);
+
const paramsRef =
useRef>>>(params);
+ useEffect(() => {
+ paramsRef.current = params;
+ }, [params]);
+
const snapshot = useRef([]);
// Ref that stores the mutation with middlewares to avoid losing them if the calling component is unmounted
const mutateWithMiddlewares = useRef(dataProvider.updateMany);