Skip to content

Commit 200b680

Browse files
committed
feat: On connection switch force a re-render by using react-key property based on connection id.
1 parent fcc8ebc commit 200b680

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

apps/dave/src/providers/DataProvider.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { CartesiProvider } from "@cartesi/wagmi";
22
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
3-
import type { FC, PropsWithChildren } from "react";
3+
import { useMemo, type FC, type PropsWithChildren } from "react";
44
import { useSelectedNodeConnection } from "../components/connection/hooks";
55
import queryClient from "./queryClient";
66
import WalletProvider from "./WalletProvider";
77

8-
const newQueryClient = new QueryClient();
9-
108
const DataProvider: FC<PropsWithChildren> = ({ children }) => {
119
const selectedConnection = useSelectedNodeConnection();
12-
13-
const client =
14-
selectedConnection?.type === "system_mock"
15-
? queryClient
16-
: newQueryClient;
10+
const client = useMemo(
11+
() =>
12+
selectedConnection?.type === "system_mock"
13+
? queryClient
14+
: new QueryClient(),
15+
[selectedConnection?.type],
16+
);
1717

1818
return (
19-
<QueryClientProvider client={client}>
19+
<QueryClientProvider client={client} key={selectedConnection?.id}>
2020
<CartesiProvider rpcUrl={selectedConnection?.url ?? ""}>
2121
<WalletProvider>{children}</WalletProvider>
2222
</CartesiProvider>

0 commit comments

Comments
 (0)