diff --git a/packages/ui-react/src/hooks/useTonAddress.ts b/packages/ui-react/src/hooks/useTonAddress.ts index 15f99c71..ceb2d04d 100644 --- a/packages/ui-react/src/hooks/useTonAddress.ts +++ b/packages/ui-react/src/hooks/useTonAddress.ts @@ -1,5 +1,6 @@ import { CHAIN, toUserFriendlyAddress } from '@tonconnect/ui'; import { useTonWallet } from './useTonWallet'; +import { useMemo } from 'react'; /** * Use it to get user's current ton wallet address. If wallet is not connected hook will return empty string. @@ -7,12 +8,16 @@ import { useTonWallet } from './useTonWallet'; */ export function useTonAddress(userFriendly = true): string { const wallet = useTonWallet(); - - if (wallet) { - return userFriendly - ? toUserFriendlyAddress(wallet.account.address, wallet.account.chain === CHAIN.TESTNET) - : wallet.account.address; - } else { - return ''; - } + return useMemo(() => { + if (wallet) { + return userFriendly + ? toUserFriendlyAddress( + wallet.account.address, + wallet.account.chain === CHAIN.TESTNET + ) + : wallet.account.address; + } else { + return ''; + } + }, [wallet, userFriendly, wallet?.account.address, wallet?.account.chain]); }