From 7ab5a8dbe0db96f671a82cd4c5df3bbb5049542e Mon Sep 17 00:00:00 2001 From: titix Date: Mon, 15 Jul 2024 16:55:00 -0300 Subject: [PATCH] fix: queryClient | remove refetch effect --- src/providers/DataProvider.tsx | 14 +++++--------- src/providers/index.tsx | 19 +++++++------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/providers/DataProvider.tsx b/src/providers/DataProvider.tsx index 720f5ba..f8d02a3 100644 --- a/src/providers/DataProvider.tsx +++ b/src/providers/DataProvider.tsx @@ -1,5 +1,5 @@ -import { createContext, useState, useEffect } from 'react'; -import { useQuery } from '@tanstack/react-query'; +import { createContext, useState, useEffect, ReactNode } from 'react'; +import { useQuery, UseQueryResult } from '@tanstack/react-query'; import { useRouter } from 'next/router'; import { ChainData, EcosystemData } from '~/types'; @@ -11,13 +11,14 @@ type ContextType = { isEcosystemLoading: boolean; isChainLoading: boolean; + refetchChainData: (options: { throwOnError: boolean; cancelRefetch: boolean }) => Promise; ecosystemData: EcosystemData; chainData: ChainData; }; interface DataProps { - children: React.ReactElement; + children: ReactNode; } export const DataContext = createContext({} as ContextType); @@ -46,12 +47,6 @@ export const DataProvider = ({ children }: DataProps) => { enabled: !!selectedChain?.chainId, }); - useEffect(() => { - if (selectedChain) { - refetchChainData(); - } - }, [selectedChain, refetchChainData]); - useEffect(() => { if (isEcosystemError || isChainError) { router.push('/error'); @@ -67,6 +62,7 @@ export const DataProvider = ({ children }: DataProps) => { isChainLoading, ecosystemData, chainData, + refetchChainData, }} > {children} diff --git a/src/providers/index.tsx b/src/providers/index.tsx index b702aa5..6bfc7e8 100644 --- a/src/providers/index.tsx +++ b/src/providers/index.tsx @@ -1,5 +1,4 @@ import type { ReactNode } from 'react'; -import { QueryClientProvider, QueryClient } from '@tanstack/react-query'; import { StateProvider } from './StateProvider'; import { ThemeProvider } from './ThemeProvider'; @@ -10,18 +9,14 @@ type Props = { children: ReactNode; }; -const queryClient = new QueryClient(); - export const Providers = ({ children }: Props) => { return ( - - - - - {children} - - - - + + + + {children} + + + ); };