mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
updated admin to use swr hooks instead of react-query
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { Api } from "Api";
|
||||
import type { FetchPromise } from "modules/ModuleApi";
|
||||
import useSWR, { type SWRConfiguration, useSWRConfig } from "swr";
|
||||
import type { FetchPromise, ResponseObject } from "modules/ModuleApi";
|
||||
import useSWR, { type SWRConfiguration } from "swr";
|
||||
import { useClient } from "ui/client/ClientProvider";
|
||||
|
||||
export const useApi = () => {
|
||||
@@ -8,13 +8,16 @@ export const useApi = () => {
|
||||
return client.api;
|
||||
};
|
||||
|
||||
export const useApiQuery = <Data, RefineFn extends (data: Data) => any = (data: Data) => Data>(
|
||||
export const useApiQuery = <
|
||||
Data,
|
||||
RefineFn extends (data: ResponseObject<Data>) => any = (data: ResponseObject<Data>) => Data
|
||||
>(
|
||||
fn: (api: Api) => FetchPromise<Data>,
|
||||
options?: SWRConfiguration & { enabled?: boolean; refine?: RefineFn }
|
||||
) => {
|
||||
const api = useApi();
|
||||
const promise = fn(api);
|
||||
const refine = options?.refine ?? ((data: Data) => data);
|
||||
const refine = options?.refine ?? ((data: ResponseObject<Data>) => data);
|
||||
const fetcher = () => promise.execute().then(refine);
|
||||
const key = promise.key();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user