Skip to content

Commit

Permalink
Add: Fix bug in login functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
predict-woo committed Apr 30, 2024
1 parent 5e51b77 commit 5364ee0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/web/src/hooks/useTaxiAPI/useSWR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useCallback, useEffect } from "react";
import useSWR from "swr";

import useAxios from "./useAxios";

type Method = "get" | "post";

const wrapUseSWR =
(method: Method) =>
(
url: string,
requestData?: any,
dep?: [any],
config?: any
): [any, any, boolean] => {
const axios = useAxios();
const fetcher = useCallback(
(url: string) => {
return axios({
url,
method,
data: requestData,
}).then((res) => res.data);
},
[JSON.stringify(requestData)]
);

const { data, error, isLoading, mutate } = useSWR(url, fetcher, config);

useEffect(() => {
if (dep) {
mutate();
}
}, [dep]);

return [error, data, isLoading];
};

export default {
get: wrapUseSWR("get"),
post: wrapUseSWR("post"),
};

0 comments on commit 5364ee0

Please sign in to comment.