refactor: sorted hooks
This commit is contained in:
31
src/hooks/lists/useDealsList.ts
Normal file
31
src/hooks/lists/useDealsList.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { DealSchema } from "@/lib/client";
|
||||
import { getDealsOptions } from "@/lib/client/@tanstack/react-query.gen";
|
||||
|
||||
type Props = {
|
||||
boardId?: number;
|
||||
};
|
||||
|
||||
const useDealsList = ({ boardId }: Props) => {
|
||||
const [deals, setDeals] = useState<DealSchema[]>([]);
|
||||
|
||||
const { data, refetch, isLoading } = useQuery({
|
||||
...getDealsOptions({ path: { boardId: boardId! } }),
|
||||
enabled: boardId !== undefined,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (boardId === undefined) {
|
||||
setDeals([]);
|
||||
return;
|
||||
}
|
||||
if (data?.deals) {
|
||||
setDeals(data.deals);
|
||||
}
|
||||
}, [data?.deals, boardId]);
|
||||
|
||||
return { deals, setDeals, refetch, isLoading };
|
||||
};
|
||||
|
||||
export default useDealsList;
|
||||
Reference in New Issue
Block a user