feat: Add staleTime

This commit is contained in:
jhynsoo 2023-11-13 23:55:30 +09:00
parent 4f9d9269f5
commit 36f3a6cd18
5 changed files with 9 additions and 17 deletions

View File

@ -9,6 +9,7 @@ const queryClient = new QueryClient({
defaultOptions: { defaultOptions: {
queries: { queries: {
suspense: true, suspense: true,
refetchOnWindowFocus: false,
}, },
}, },
}); });

View File

@ -8,7 +8,7 @@ const getBrands = async () => {
export const useBrands = () => { export const useBrands = () => {
const data = useQuery('brands', () => getBrands(), { const data = useQuery('brands', () => getBrands(), {
suspense: true, staleTime: 1000 * 60 * 60 * 24,
}); });
return data; return data;
@ -21,7 +21,7 @@ const getBrand = async (id) => {
export const useBrand = (id) => { export const useBrand = (id) => {
const data = useQuery(['products', id], () => getBrand(id), { const data = useQuery(['products', id], () => getBrand(id), {
suspense: true, staleTime: 1000 * 60 * 60 * 24,
}); });
return data; return data;
@ -33,9 +33,7 @@ const getBrandProduct = async (id) => {
}; };
export const useBrandProduct = (id) => { export const useBrandProduct = (id) => {
const data = useQuery(['brandproduct', id], () => getBrandProduct(id), { const data = useQuery(['brandproduct', id], () => getBrandProduct(id));
suspense: true,
});
return data; return data;
}; };

View File

@ -8,7 +8,7 @@ const getGraph = async (id) => {
export const useGraph = (id) => { export const useGraph = (id) => {
const data = useQuery(['post', id], () => getGraph(id), { const data = useQuery(['post', id], () => getGraph(id), {
suspense: true, staleTime: 1000 * 60 * 60 * 24,
}); });
return data; return data;

View File

@ -11,9 +11,7 @@ const getPosts = async ({ my, page }) => {
}; };
export const usePosts = ({ my, page }) => { export const usePosts = ({ my, page }) => {
const data = useQuery(['post', my, page], () => getPosts({ my, page }), { const data = useQuery(['post', my, page], () => getPosts({ my, page }));
suspense: true,
});
return data; return data;
}; };
@ -24,9 +22,7 @@ const getPost = async (id) => {
}; };
export const usePost = (id) => { export const usePost = (id) => {
const data = useQuery(['post', id], () => getPost(id), { const data = useQuery(['post', id], () => getPost(id));
suspense: true,
});
return data; return data;
}; };

View File

@ -8,7 +8,7 @@ const getProducts = async () => {
export const useProducts = () => { export const useProducts = () => {
const data = useQuery('products', () => getProducts(), { const data = useQuery('products', () => getProducts(), {
suspense: true, staleTime: 1000 * 60 * 60 * 24,
}); });
return data; return data;
@ -21,7 +21,7 @@ const getProduct = async (id) => {
export const useProduct = (id) => { export const useProduct = (id) => {
const data = useQuery(['product', id], () => getProduct(id), { const data = useQuery(['product', id], () => getProduct(id), {
suspense: true, staleTime: 1000 * 60 * 60 * 24,
}); });
return data; return data;
@ -37,9 +37,6 @@ export const useProductPost = ({ id, page }) => {
const data = useQuery( const data = useQuery(
['productpost', id], ['productpost', id],
() => getProductPost({ id, page }), () => getProductPost({ id, page }),
{
suspense: true,
}
); );
return data; return data;