Skip to content

Commit

Permalink
chore: react-query has been migrated to version 5 and several changes…
Browse files Browse the repository at this point in the history
… have been made
  • Loading branch information
Franqsanz committed Nov 6, 2023
1 parent 8f5c0f1 commit 31e42ac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/components/AllBooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import { SkeletonAllBooks } from './skeletons/SkeletonABooks';

export function AllBooks() {
const { ref, inView } = useInView();
const { data, isLoading, error, fetchNextPage, isFetchingNextPage } =
const { data, isPending, error, fetchNextPage, isFetchingNextPage } =
useBooksPaginate();
let fetchingNextPageUI;

useEffect(() => {
if (inView) fetchNextPage();
}, [inView]);

if (isLoading) {
if (isPending) {
return <SkeletonAllBooks showTags={false} />;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/NewBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function FormNewBook() {
const bgColorBox = useColorModeValue('white', 'gray.900');
const bgColorInput = useColorModeValue('gray.100', 'gray.800');
const bgColorButton = useColorModeValue('green.500', 'green.700');
const { mutate, isLoading, isSuccess, error } = useMutatePost();
const { mutate, isPending, isSuccess, error } = useMutatePost();
const [cropData, setCropData] = useState<string | null>(null);
const [previewImg, setPreviewImg] = useState<Blob | MediaSource | null>(null);
const [crop, setCrop] = useState<any>('');
Expand Down Expand Up @@ -621,7 +621,7 @@ export function FormNewBook() {
_active={{ bg: 'green.600' }}
isDisabled={disabled}
loadingText='Publicando...'
isLoading={isLoading}
isLoading={isPending}
>
<Icon as={AiOutlineCloudUpload} fontSize='25' mr='2' />
Publicar
Expand Down
4 changes: 2 additions & 2 deletions src/components/forms/filters/InputSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function InputSearch({
let alertMessage;
let loading;

const { data, error, isLoading, refetch } = useAllSearchBooks(debouncedQuery);
const { data, error, isPending, refetch } = useAllSearchBooks(debouncedQuery);

useOutsideClick({
ref: containerRef,
Expand Down Expand Up @@ -93,7 +93,7 @@ export function InputSearch({
};
}, [debouncedQuery, refetch]);

if (isLoading) {
if (isPending) {
loading = (
<Flex justify='center' direction='column' align='center' gap='2'>
<Spinner size='md' thickness='2px' speed='0.40s' />
Expand Down
32 changes: 15 additions & 17 deletions src/hooks/querys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
useQuery,
useSuspenseQuery,
useMutation,
useInfiniteQuery,
QueryClient,
Expand Down Expand Up @@ -28,7 +29,7 @@ function useMutatePost() {
// Mutación optimista
onMutate: async (newPost) => {
// Cancelar consultas pendientes para la misma clave de consulta
await queryClient.cancelQueries([keys.postBook]);
await queryClient.cancelQueries({ queryKey: [keys.postBook] });

// Obtener los datos de la consulta anterior
const previousPost = await queryClient.getQueryData([keys.postBook]);
Expand Down Expand Up @@ -85,7 +86,8 @@ function useAllFilterOptions() {
function useBooksPaginate() {
return useInfiniteQuery({
queryKey: [keys.paginate],
queryFn: ({ pageParam = 0 }) => getBooksPaginate(pageParam),
queryFn: ({ pageParam }) => getBooksPaginate(pageParam),
initialPageParam: 0,
getNextPageParam: (lastPage) => {
if (lastPage.info.nextPage === null) return;

Expand All @@ -95,43 +97,39 @@ function useBooksPaginate() {
}

function useFilter(query: string | undefined, param: string | undefined) {
return useQuery({
return useSuspenseQuery({
queryKey: [keys.filter, query, param],
queryFn: () => getBooksFilter(query, param),
suspense: true,
cacheTime: 3000,
gcTime: 3000,
});
}

function useMoreBooks() {
return useQuery({
return useSuspenseQuery({
queryKey: [keys.random],
queryFn: getMoreBooks,
suspense: true,
refetchOnWindowFocus: false,
cacheTime: 3000,
staleTime: 60000,
gcTime: 3000,
staleTime: 50000,
});
}

function useRelatedBooks(id: string | undefined) {
return useQuery({
queryKey: [keys.relatedBooks],
return useSuspenseQuery({
queryKey: [keys.relatedBooks, id],
queryFn: () => getRelatedBooks(id),
suspense: true,
refetchOnWindowFocus: false,
cacheTime: 3000,
staleTime: 60000,
gcTime: 3000,
staleTime: 50000,
});
}

function useBook(pathUrl: string | undefined) {
return useQuery({
return useSuspenseQuery({
queryKey: [keys.one, pathUrl],
queryFn: () => getBook(pathUrl),
refetchOnWindowFocus: false,
suspense: true,
cacheTime: 3000,
gcTime: 3000,
});
}

Expand Down

1 comment on commit 31e42ac

@vercel
Copy link

@vercel vercel bot commented on 31e42ac Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-franqsanz.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.