implement tanstack and fetch all data
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { blogService, IBlogQueryParams } from "@/api/services/blog.service";
|
||||
import { queryKeys } from "@/utils/queryKeys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
|
||||
export const useBlogs = (params?: IBlogQueryParams) => {
|
||||
return useQuery({
|
||||
queryKey: [...queryKeys.blogs, params],
|
||||
queryFn: () => blogService.getBlogs(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useBlogById = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.blog(id),
|
||||
queryFn: () => blogService.getBlogById(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { IProjectsQueryParams, projectsService } from "@/api/services/project.service";
|
||||
import { queryKeys } from "@/utils/queryKeys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
|
||||
export const useProjects = (params?: IProjectsQueryParams) => {
|
||||
return useQuery({
|
||||
queryKey: [...queryKeys.projects, params],
|
||||
queryFn: () => projectsService.getProjects(params),
|
||||
});
|
||||
};
|
||||
|
||||
export const useProjectById = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.project(id),
|
||||
queryFn: () => projectsService.getProjectById(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { reviewsService } from "@/api/services/review.service";
|
||||
import { queryKeys } from "@/utils/queryKeys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
|
||||
export const useReviews = () => {
|
||||
return useQuery({
|
||||
queryKey: [...queryKeys.reviews],
|
||||
queryFn: () => reviewsService.getReviews(),
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import { teamService } from "@/api/services/team.service";
|
||||
import { queryKeys } from "@/utils/queryKeys";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
|
||||
export const useTeam = () => {
|
||||
return useQuery({
|
||||
queryKey: [...queryKeys.team],
|
||||
queryFn: () => teamService.getTeams(),
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user