Skip to content

Commit 97e2b6a

Browse files
committed
fix with useCallback
1 parent d482dd3 commit 97e2b6a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/App.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./styles/App.css";
22

33
import { Porto } from "porto";
4-
import { useEffect, useMemo, useRef, useState } from "react";
4+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
55
import { type Address, type Chain, createWalletClient, custom } from "viem";
66
import { getAddresses, requestAddresses, waitForTransactionReceipt } from "viem/actions";
77
import {
@@ -196,7 +196,7 @@ export function App() {
196196
}
197197
};
198198

199-
const resetClientState = async () => {
199+
const resetClientState = useCallback(async () => {
200200
setPending(null);
201201
setLastTxHash(null);
202202
setLastTxReceipt(null);
@@ -209,11 +209,11 @@ export function App() {
209209
try {
210210
await api("/api/connection", "POST", null);
211211
} catch {}
212-
};
212+
}, []);
213213

214214
useEffect(() => {
215215
if (selectedUuid) resetClientState();
216-
}, [selectedUuid]);
216+
}, [selectedUuid, resetClientState]);
217217

218218
useEffect(() => {
219219
if (providers.length === 1 && !selected) {
@@ -307,15 +307,17 @@ export function App() {
307307

308308
{providers.length === 0 && <p>No wallets found.</p>}
309309

310-
{selected && account && (<>
311-
<div className="section-title">Connected</div>
312-
<pre className="box">
313-
{`\
310+
{selected && account && (
311+
<>
312+
<div className="section-title">Connected</div>
313+
<pre className="box">
314+
{`\
314315
account: ${account}
315316
chain: ${chain ? `${chain.name} (${chainId})` : (chainId ?? "unknown")}
316317
rpc: ${chain?.rpcUrls?.default?.http?.[0] ?? chain?.rpcUrls?.public?.http?.[0] ?? "unknown"}`}
317-
</pre>
318-
</>)}
318+
</pre>
319+
</>
320+
)}
319321

320322
{selected ? (
321323
!account && (
@@ -341,7 +343,7 @@ rpc: ${chain?.rpcUrls?.default?.http?.[0] ?? chain?.rpcUrls?.public?.http?.[
341343
<div>
342344
<div className="section-title">Transaction Hash</div>
343345
<pre className="box">{lastTxHash}</pre>
344-
346+
345347
<div>
346348
<div className="section-title">Receipt</div>
347349
<pre className="box">

0 commit comments

Comments
 (0)