`useAccount()` returns empty `address` in `useEffect()` after auto connect on page load
Closed this issue · 1 comments
Version: "@starknet-react/core": "^3.6.2"
Using the Argent Chrome extension
Description:
There appears to be an issue on page load when updating the account address with the useAccount()
hook. Specifically, the wallet correctly connects and the connected connector updates, but the wallet address cannot be read from the account
object returned from the useAccount()
hook. If the wallet is not connected on page load and I manually call connect()
from the useConnect()
hook, account.address
initializes properly. Additionally, the address
variable returned directly from the useAccount()
hook updates regardless of how the connector is initialized, but account.address
updates to a blank string when automatically connecting on page load.
Snippet:
useEffect(() => {
console.log("Account address: " + account?.address);
}, [account]);
or
useEffect(() => {
console.log("Account address: " + account?.address);
}, [account?.address]);
Console log in react strict mode (useEffects run twice):
Account address: undefined
Account address: undefined
Account address:
Account address:
Note that the wallet automatically connects to trigger the account.address
value change from undefined
to a blank string.
The AccountInterface
object from starknet.js still has the address field but it's not populated by wallets. I recommend using the address
value returned by useAccount
.