mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
upgrade alova to v3
This commit is contained in:
@@ -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 });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user