Skip to content

Commit

Permalink
Merge pull request #118 from EveripediaNetwork/fix-make-use-of-useeff…
Browse files Browse the repository at this point in the history
…ect-for-getwagmiconfig-and-query-client

make use of useEffect for getWagmiConfig and query client
  • Loading branch information
Royal-lobster authored Jan 2, 2025
2 parents 5f4e5bf + b87ae11 commit e0a1ee2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-beds-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@everipedia/iq-login": patch
---

make use of useEffect for getWagmiConfig and query client
40 changes: 16 additions & 24 deletions src/components/iq-login-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use client";

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { structuralSharing } from "@wagmi/core/query";
import type React from "react";
import { createContext } from "react";
import { createContext, useState } from "react";
import { cookieToInitialState, WagmiProvider } from "wagmi";
import {
getWagmiConfig,
Expand All @@ -22,9 +24,20 @@ export function IqLoginProvider({
cookie,
projectName,
}: IqLoginProviderProps) {
const wagmiConfig = getWagmiConfig();
const [wagmiConfig] = useState(() => getWagmiConfig());
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000,
structuralSharing,
},
},
}),
);

const initialStates = cookieToInitialState(wagmiConfig, cookie);
const queryClient = getQueryClient();

return (
<ProjectContext.Provider value={projectName}>
Expand All @@ -38,24 +51,3 @@ export function IqLoginProvider({
</ProjectContext.Provider>
);
}

function makeQueryClient() {
return new QueryClient({
defaultOptions: {
queries: {
staleTime: 60 * 1000,
structuralSharing,
},
},
});
}

let browserQueryClient: QueryClient | undefined = undefined;

function getQueryClient() {
if (typeof window === "undefined") {
return makeQueryClient();
}
if (!browserQueryClient) browserQueryClient = makeQueryClient();
return browserQueryClient;
}

0 comments on commit e0a1ee2

Please sign in to comment.