upgrade alova to v3

This commit is contained in:
proddy
2024-08-03 15:35:54 +02:00
parent 9a23d4e2b3
commit 7751baf8bf
33 changed files with 481 additions and 867 deletions

View File

@@ -2,14 +2,13 @@ import { useState } from 'react';
import { useBlocker } from 'react-router-dom';
import { toast } from 'react-toastify';
import { type Method, useRequest } from 'alova';
import type { AlovaGenerics, Method } from 'alova';
import { useRequest } from 'alova/client';
import { useI18nContext } from 'i18n/i18n-react';
export interface RestRequestOptions<D> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
read: () => Method<any, any, any, any, any, any, any>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
update: (value: D) => Method<any, any, any, any, any, any, any>;
read: () => Method<AlovaGenerics>;
update: (value: D) => Method<AlovaGenerics>;
}
export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
@@ -26,12 +25,14 @@ export const useRest = <D>({ read, update }: RestRequestOptions<D>) => {
data,
send: readData,
update: updateData,
// TODO refactor
onComplete: onReadComplete
} = useRequest(read());
const {
loading: saving,
send: writeData,
// TODO refactor
onSuccess: onWriteSuccess
} = useRequest((newData: D) => update(newData), { immediate: false });