Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useAccount() returns empty address in useEffect() after auto connect on page load #541

Open
jbettenc opened this issue Dec 2, 2024 · 0 comments

Comments

@jbettenc
Copy link

jbettenc commented Dec 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant