mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-23 23:05:46 +00:00
fix: memoized formattedSuccessRawData and formattedErrorRawData
This commit is contained in:
@@ -566,23 +566,31 @@ const useSelect = <T,>(
|
|||||||
setSize(size + 1);
|
setSize(size + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
let formattedSuccessRawData: SuccessApiResponse<T[]> | undefined = undefined;
|
|
||||||
let formattedErrorRawData: ErrorApiResponse | undefined = undefined;
|
|
||||||
|
|
||||||
const latestPagesIndex = pages?.length ? pages.length - 1 : 0;
|
const latestPagesIndex = pages?.length ? pages.length - 1 : 0;
|
||||||
|
|
||||||
if (isResponseSuccess(pages?.[latestPagesIndex])) {
|
const { formattedSuccessRawData, formattedErrorRawData } = useMemo(() => {
|
||||||
formattedSuccessRawData = {
|
let successData: SuccessApiResponse<T[]> | undefined = undefined;
|
||||||
...pages?.[latestPagesIndex],
|
let errorData: ErrorApiResponse | undefined = undefined;
|
||||||
data:
|
|
||||||
pages?.flatMap((page) => (isResponseSuccess(page) ? page.data : [])) ??
|
|
||||||
[],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isResponseError(pages?.[latestPagesIndex])) {
|
if (isResponseSuccess(pages?.[latestPagesIndex])) {
|
||||||
formattedErrorRawData = pages?.[latestPagesIndex];
|
successData = {
|
||||||
}
|
...pages![latestPagesIndex],
|
||||||
|
data:
|
||||||
|
pages?.flatMap((page) =>
|
||||||
|
isResponseSuccess(page) ? page.data : []
|
||||||
|
) ?? [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isResponseError(pages?.[latestPagesIndex])) {
|
||||||
|
errorData = pages![latestPagesIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
formattedSuccessRawData: successData,
|
||||||
|
formattedErrorRawData: errorData,
|
||||||
|
};
|
||||||
|
}, [pages, latestPagesIndex]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputValue,
|
inputValue,
|
||||||
|
|||||||
Reference in New Issue
Block a user