Skip to content

Commit

Permalink
refactor: move query client provider to a client component
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinx0 committed Nov 6, 2024
1 parent db47958 commit 80f4abf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@ import { TownsProvider } from '@/context/TownProvider';
import { createClient } from '@/lib/supabase/server';
import { SessionProvider } from '@/context/SessionProvider';
import { townsService } from '@/lib/service';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Toaster } from 'sonner';
import { PropsWithChildren } from 'react';
import { QueryClientProvider } from '@/context/QueryClientProvider';

export const metadata = {
title: 'Ajuda Dana - Sistema de Coordinación',
description: 'Sistema de coordinación para emergencias en la Comunidad Valenciana',
};

const queryClient = new QueryClient();

const getSession = async () => {
const supabase = await createClient();
const { data, error } = await supabase.auth.getUser();
return data;
};

export default async function RootLayout({ children }: PropsWithChildren<{}>) {
export default async function RootLayout({ children }: PropsWithChildren) {
const session = await getSession();
const towns = await townsService.getTowns();
return (
<html lang="es">
<body suppressHydrationWarning={true}>
<Toaster position="bottom-left" richColors />
<SessionProvider session={session}>
<QueryClientProvider client={queryClient}>
<QueryClientProvider>
<TownsProvider towns={towns}>
<EmergencyProvider>
<EmergencyLayout>{children}</EmergencyLayout>
Expand Down
10 changes: 10 additions & 0 deletions src/context/QueryClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use client';

import { PropsWithChildren, useState } from 'react';
import { QueryClient, QueryClientProvider as TanstackQueryClientProvider } from '@tanstack/react-query';

export const QueryClientProvider = ({ children }: PropsWithChildren) => {
const [client] = useState(new QueryClient());

return <TanstackQueryClientProvider client={client}>{children}</TanstackQueryClientProvider>;
};

0 comments on commit 80f4abf

Please sign in to comment.