Skip to content

Commit

Permalink
chore: update react-query to v5.28
Browse files Browse the repository at this point in the history
  • Loading branch information
davy-beauzil committed Apr 8, 2024
1 parent 8cb0aa8 commit 5207327
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
6 changes: 3 additions & 3 deletions templates/next/components/common/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ReactNode, useState } from "react";
import { DehydratedState, Hydrate, QueryClient, QueryClientProvider } from "react-query";
import { DehydratedState, HydrationBoundary, QueryClient, QueryClientProvider } from "@tanstack/react-query";

const Layout = ({ children, dehydratedState }: { children: ReactNode, dehydratedState: DehydratedState }) => {
const [queryClient] = useState(() => new QueryClient());

return (
<QueryClientProvider client={queryClient}>
<Hydrate state={dehydratedState}>
<HydrationBoundary state={dehydratedState}>
{children}
</Hydrate>
</HydrationBoundary>
</QueryClientProvider>
);
}
Expand Down
26 changes: 14 additions & 12 deletions templates/next/components/foo/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FunctionComponent, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/router";
import { ErrorMessage{{#if hasManyRelations}}, Field, FieldArray{{/if}}, Formik } from "formik";
import { useMutation } from "react-query";
import { useMutation } from "@tanstack/react-query";

import { fetchApi, FetchError, FetchResponse } from "../../utils/dataAccess";
import { {{{ucf}}} } from '../../types/{{{ucf}}}';
Expand Down Expand Up @@ -31,17 +31,19 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
const [, setError] = useState<string | null>(null);
const router = useRouter();

const saveMutation = useMutation<FetchResponse<{{ucf}}> | undefined, Error|FetchError, SaveParams>((saveParams) => save{{{ucf}}}(saveParams));
const saveMutation = useMutation<FetchResponse<{{ucf}}> | undefined, Error|FetchError, SaveParams>({mutationFn: (saveParams) => save{{{ucf}}}(saveParams)});

const deleteMutation = useMutation<FetchResponse<{{ucf}}> | undefined, Error|FetchError, DeleteParams>(({ id }) => delete{{{ucf}}}(id), {
onSuccess: () => {
router.push("/{{{lc}}}s");
},
onError: (error)=> {
setError(`Error when deleting the resource: ${error}`);
console.error(error);
}
});
const deleteMutation = useMutation<FetchResponse<{{ucf}}> | undefined, Error|FetchError, DeleteParams>(
{
mutationFn: ({ id }) => delete{{{ucf}}}(id),
onSuccess: () => {
router.push("/{{{lc}}}s");
},
onError: (error)=> {
setError(`Error when deleting the resource: ${error}`);
console.error(error);
},
});

const handleDelete = () => {
if (!{{lc}} || !{{lc}}["@id"]) return;
Expand Down Expand Up @@ -90,7 +92,7 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {
isValid: true,
msg: `Element ${isCreation ? "created" : "updated"}.`,
});
router.push("/{{{name}}}");
router.push("/{{{lc}}}s");
},
onError: (error) => {
setStatus({
Expand Down
4 changes: 2 additions & 2 deletions templates/next/components/foo/PageList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextComponentType, NextPageContext } from "next";
import { useRouter } from "next/router";
import Head from "next/head";
import { useQuery } from "react-query";
import { useQuery } from "@tanstack/react-query";

import Pagination from "../common/Pagination";
import { List } from "./List";
Expand All @@ -17,7 +17,7 @@ const getPagePath = (path: string) => `/{{{lc}}}s/page/${parsePage("{{{name}}}",
export const PageList: NextComponentType<NextPageContext> = () => {
const { query: { page } } = useRouter();
const { data: { data: {{lc}}s, hubURL } = { hubURL: null } } =
useQuery<FetchResponse<PagedCollection<{{{ucf}}}>> | undefined>(get{{{ucf}}}sPath(page), get{{{ucf}}}s(page));
useQuery<FetchResponse<PagedCollection<{{{ucf}}}>> | undefined, Error, FetchResponse<PagedCollection<{{{ucf}}}>> | undefined>({queryKey: [get{{{ucf}}}sPath(page)], queryFn: get{{{ucf}}}s(page)});
const collection = useMercure({{lc}}s, hubURL);

if (!collection || !collection["{{{hydraPrefix}}}member"]) return null;
Expand Down
2 changes: 1 addition & 1 deletion templates/next/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "../styles/style.css";
import type { AppProps } from "next/app";
import type { DehydratedState } from "react-query";
import type { DehydratedState } from "@tanstack/react-query";

import Layout from "../components/common/Layout";

Expand Down
6 changes: 3 additions & 3 deletions templates/next/pages/foos/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetStaticPaths, GetStaticProps, NextComponentType, NextPageContext } fr
import DefaultErrorPage from "next/error";
import Head from "next/head";
import { useRouter } from "next/router";
import { dehydrate, QueryClient, useQuery } from "react-query";
import { dehydrate, QueryClient, useQuery } from "@tanstack/react-query";

import { Form } from "../../../components/{{{lc}}}/Form";
import { PagedCollection } from "../../../types/collection";
Expand All @@ -15,7 +15,7 @@ const Page: NextComponentType<NextPageContext> = () => {
const router = useRouter();
const { id } = router.query;

const { data: { data: {{lc}} } = {} } = useQuery<FetchResponse<{{{ucf}}}> | undefined>(['{{{lc}}}', id], () => get{{{ucf}}}(id));
const { data: { data: {{lc}} } = {} } = useQuery<FetchResponse<{{{ucf}}}> | undefined, Error, FetchResponse<{{{ucf}}}> | undefined>({queryKey: ['{{{lc}}}', id], queryFn: () => get{{{ucf}}}(id)});

if (!{{{lc}}}) {
return <DefaultErrorPage statusCode={404} />;
Expand All @@ -36,7 +36,7 @@ const Page: NextComponentType<NextPageContext> = () => {
export const getStaticProps: GetStaticProps = async ({ params: { id } = {} }) => {
if (!id) throw new Error('id not in query param');
const queryClient = new QueryClient();
await queryClient.prefetchQuery(["{{{lc}}}", id], () => get{{{ucf}}}(id));
await queryClient.prefetchQuery({queryKey: ["{{{lc}}}", id], queryFn: () => get{{{ucf}}}(id)});

return {
props: {
Expand Down
6 changes: 3 additions & 3 deletions templates/next/pages/foos/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetStaticPaths, GetStaticProps, NextComponentType, NextPageContext } fr
import DefaultErrorPage from "next/error";
import Head from "next/head";
import { useRouter } from "next/router";
import { dehydrate, QueryClient, useQuery } from "react-query";
import { dehydrate, QueryClient, useQuery } from "@tanstack/react-query";

import { Show } from "../../../components/{{{lc}}}/Show";
import { PagedCollection } from "../../../types/collection";
Expand All @@ -17,7 +17,7 @@ const Page: NextComponentType<NextPageContext> = () => {
const { id } = router.query;

const { data: { data: {{lc}}, hubURL, text } = { hubURL: null, text: '' } } =
useQuery<FetchResponse<{{{ucf}}}> | undefined>(['{{{lc}}}', id], () => get{{{ucf}}}(id));
useQuery<FetchResponse<{{{ucf}}}> | undefined, Error, FetchResponse<{{{ucf}}}> | undefined>({queryKey: ['{{{lc}}}', id], queryFn: () => get{{{ucf}}}(id)});
const {{{lc}}}Data = useMercure({{lc}}, hubURL);

if (!{{{lc}}}Data) {
Expand All @@ -39,7 +39,7 @@ const Page: NextComponentType<NextPageContext> = () => {
export const getStaticProps: GetStaticProps = async ({ params: { id } = {} }) => {
if (!id) throw new Error('id not in query param');
const queryClient = new QueryClient();
await queryClient.prefetchQuery(["{{{lc}}}", id], () => get{{{ucf}}}(id));
await queryClient.prefetchQuery({queryKey: ["{{{lc}}}", id], queryFn: () => get{{{ucf}}}(id)});

return {
props: {
Expand Down
4 changes: 2 additions & 2 deletions templates/next/pages/foos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GetStaticProps } from "next";
import { dehydrate, QueryClient } from "react-query";
import { dehydrate, QueryClient } from "@tanstack/react-query";

import { PageList, get{{{ucf}}}s, get{{{ucf}}}sPath } from "../../components/{{{lc}}}/PageList";

export const getStaticProps: GetStaticProps = async () => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery(get{{{ucf}}}sPath(), get{{{ucf}}}s());
await queryClient.prefetchQuery({queryKey: [get{{{ucf}}}sPath()], queryFn: get{{{ucf}}}s()});

return {
props: {
Expand Down
4 changes: 2 additions & 2 deletions templates/next/pages/foos/page/[page].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GetStaticPaths, GetStaticProps } from "next";
import { dehydrate, QueryClient } from "react-query";
import { dehydrate, QueryClient } from "@tanstack/react-query";

import { PageList, get{{{ucf}}}s, get{{{ucf}}}sPath } from "../../../components/{{{lc}}}/PageList";
import { PagedCollection } from "../../../types/collection";
Expand All @@ -8,7 +8,7 @@ import { fetchApi, getCollectionPaths } from "../../../utils/dataAccess";

export const getStaticProps: GetStaticProps = async ({ params: { page } = {} }) => {
const queryClient = new QueryClient();
await queryClient.prefetchQuery(get{{{ucf}}}sPath(page), get{{{ucf}}}s(page));
await queryClient.prefetchQuery({queryKey: [get{{{ucf}}}sPath(page)], queryFn: get{{{ucf}}}s(page)});

return {
props: {
Expand Down

0 comments on commit 5207327

Please sign in to comment.