T
TanStack2y ago
extended-salmon

Can I use the Loading from app directory for the isLoading State in RQ?

'use client';

import NavBar from "@/components/NavBar";
import Footer from "@/components/Footer";
import { useQuery } from "@tanstack/react-query";
import getUsername from "@/functions/getUsername";
import Loading from "./loading";
import { getCookie } from "cookies-next";
export default function Layout({ children }: { children: React.ReactNode }) {
const {data , isLoading} = useQuery<any>({
queryKey : ["profileData"],
queryFn : () => getUsername(getCookie("fresh_tomatoes_auth_token"))
})
if(isLoading || !data) {
return <Loading/>; // The default loading component from loading.tsx
} else {
return (
<>
<NavBar username={data.userExists.username} />
<main>{children}</main>
<Footer />
</>
);
}
}
'use client';

import NavBar from "@/components/NavBar";
import Footer from "@/components/Footer";
import { useQuery } from "@tanstack/react-query";
import getUsername from "@/functions/getUsername";
import Loading from "./loading";
import { getCookie } from "cookies-next";
export default function Layout({ children }: { children: React.ReactNode }) {
const {data , isLoading} = useQuery<any>({
queryKey : ["profileData"],
queryFn : () => getUsername(getCookie("fresh_tomatoes_auth_token"))
})
if(isLoading || !data) {
return <Loading/>; // The default loading component from loading.tsx
} else {
return (
<>
<NavBar username={data.userExists.username} />
<main>{children}</main>
<Footer />
</>
);
}
}
I'm well aware that the loading component is only for server components, however, I was wondering if this this was a safe method to show loading status. Cheers and Thanks!
1 Reply
noble-gold
noble-gold2y ago
If it works… I see no issue

Did you find this page helpful?