Skip to content

Commit

Permalink
fix: queryClient | remove refetch effect
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtiti committed Jul 15, 2024
1 parent a0ca85a commit 7ab5a8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
14 changes: 5 additions & 9 deletions src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,13 +11,14 @@ type ContextType = {

isEcosystemLoading: boolean;
isChainLoading: boolean;
refetchChainData: (options: { throwOnError: boolean; cancelRefetch: boolean }) => Promise<UseQueryResult>;

ecosystemData: EcosystemData;
chainData: ChainData;
};

interface DataProps {
children: React.ReactElement;
children: ReactNode;
}

export const DataContext = createContext({} as ContextType);
Expand Down Expand Up @@ -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');
Expand All @@ -67,6 +62,7 @@ export const DataProvider = ({ children }: DataProps) => {
isChainLoading,
ecosystemData,
chainData,
refetchChainData,
}}
>
{children}
Expand Down
19 changes: 7 additions & 12 deletions src/providers/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ReactNode } from 'react';
import { QueryClientProvider, QueryClient } from '@tanstack/react-query';

import { StateProvider } from './StateProvider';
import { ThemeProvider } from './ThemeProvider';
Expand All @@ -10,18 +9,14 @@ type Props = {
children: ReactNode;
};

const queryClient = new QueryClient();

export const Providers = ({ children }: Props) => {
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
<StateProvider>
<DataProvider>
<WalletProvider>{children}</WalletProvider>
</DataProvider>
</StateProvider>
</ThemeProvider>
</QueryClientProvider>
<ThemeProvider>
<StateProvider>
<WalletProvider>
<DataProvider>{children}</DataProvider>
</WalletProvider>
</StateProvider>
</ThemeProvider>
);
};

0 comments on commit 7ab5a8d

Please sign in to comment.