@refinedev/core 5.0.5 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/hooks/data/useList.d.cts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/form/index.d.cts.map +1 -1
- package/dist/hooks/form/index.d.ts.map +1 -1
- package/dist/index.cjs +477 -454
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +56 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/hooks/data/useList.ts +34 -22
- package/src/hooks/form/index.ts +20 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Refine is a React meta-framework for building enterprise-level, data-intensive applications rapidly with support for modern UI libraries and headless integrations.",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
|
|
3
3
|
import { getXRay } from "@refinedev/devtools-internal";
|
|
4
|
+
import { useMemo } from "react";
|
|
4
5
|
import {
|
|
5
6
|
type QueryObserverResult,
|
|
6
7
|
type UseQueryOptions,
|
|
@@ -200,6 +201,38 @@ export const useList = <
|
|
|
200
201
|
},
|
|
201
202
|
});
|
|
202
203
|
|
|
204
|
+
// Memoize the select function to prevent it from running multiple times
|
|
205
|
+
// Note: If queryOptions.select is not memoized by the user, this will still
|
|
206
|
+
// re-run on every render. Users should wrap their select function in useCallback.
|
|
207
|
+
const memoizedSelect = useMemo(() => {
|
|
208
|
+
return (rawData: GetListResponse<TQueryFnData>): GetListResponse<TData> => {
|
|
209
|
+
let data = rawData;
|
|
210
|
+
|
|
211
|
+
if (prefferedPagination.mode === "client") {
|
|
212
|
+
data = {
|
|
213
|
+
...data,
|
|
214
|
+
data: data.data.slice(
|
|
215
|
+
(prefferedPagination.currentPage - 1) *
|
|
216
|
+
prefferedPagination.pageSize,
|
|
217
|
+
prefferedPagination.currentPage * prefferedPagination.pageSize,
|
|
218
|
+
),
|
|
219
|
+
total: data.total,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (queryOptions?.select) {
|
|
224
|
+
return queryOptions?.select?.(data);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return data as unknown as GetListResponse<TData>;
|
|
228
|
+
};
|
|
229
|
+
}, [
|
|
230
|
+
prefferedPagination.currentPage,
|
|
231
|
+
prefferedPagination.pageSize,
|
|
232
|
+
prefferedPagination.mode,
|
|
233
|
+
queryOptions?.select,
|
|
234
|
+
]);
|
|
235
|
+
|
|
203
236
|
const queryResponse = useQuery<
|
|
204
237
|
GetListResponse<TQueryFnData>,
|
|
205
238
|
TError,
|
|
@@ -238,28 +271,7 @@ export const useList = <
|
|
|
238
271
|
typeof queryOptions?.enabled !== "undefined"
|
|
239
272
|
? queryOptions?.enabled
|
|
240
273
|
: !!resource?.name,
|
|
241
|
-
select:
|
|
242
|
-
let data = rawData;
|
|
243
|
-
|
|
244
|
-
const { currentPage, mode, pageSize } = prefferedPagination;
|
|
245
|
-
|
|
246
|
-
if (mode === "client") {
|
|
247
|
-
data = {
|
|
248
|
-
...data,
|
|
249
|
-
data: data.data.slice(
|
|
250
|
-
(currentPage - 1) * pageSize,
|
|
251
|
-
currentPage * pageSize,
|
|
252
|
-
),
|
|
253
|
-
total: data.total,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (queryOptions?.select) {
|
|
258
|
-
return queryOptions?.select?.(data);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
return data as unknown as GetListResponse<TData>;
|
|
262
|
-
},
|
|
274
|
+
select: memoizedSelect,
|
|
263
275
|
meta: {
|
|
264
276
|
...queryOptions?.meta,
|
|
265
277
|
...getXRay("useList", resource?.name),
|
package/src/hooks/form/index.ts
CHANGED
|
@@ -302,12 +302,28 @@ export const useForm = <
|
|
|
302
302
|
return submissionPromise;
|
|
303
303
|
};
|
|
304
304
|
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
305
|
+
const onFinishRef = React.useRef(onFinish);
|
|
306
|
+
React.useEffect(() => {
|
|
307
|
+
onFinishRef.current = onFinish;
|
|
308
|
+
}, [onFinish]);
|
|
309
|
+
|
|
310
|
+
const onFinishAutoSave = React.useMemo(
|
|
311
|
+
() =>
|
|
312
|
+
asyncDebounce(
|
|
313
|
+
(values: TVariables) =>
|
|
314
|
+
onFinishRef.current(values, { isAutosave: true }),
|
|
315
|
+
props.autoSave?.debounce ?? 1000,
|
|
316
|
+
"Cancelled by debounce",
|
|
317
|
+
),
|
|
318
|
+
[props.autoSave?.debounce],
|
|
309
319
|
);
|
|
310
320
|
|
|
321
|
+
React.useEffect(() => {
|
|
322
|
+
return () => {
|
|
323
|
+
onFinishAutoSave.cancel();
|
|
324
|
+
};
|
|
325
|
+
}, [onFinishAutoSave]);
|
|
326
|
+
|
|
311
327
|
const overtime = {
|
|
312
328
|
elapsedTime,
|
|
313
329
|
};
|