I’m using React Moralis for a web app in which the user connects their wallet using a web3uikit ConnectButton with moralis auth. I need to know the user’s wallet address based on which account they’re currently using, and using user.get("ethAddress")
works, but when I change wallet accounts the following code still prints that I am on the original account that logged in
const [userAddress, setAddress] = useState("0")
useEffect(() => {
if (isAuthenticated) {
setAddress(user!.get("ethAddress").toLowerCase())
console.log(`user address: ${userAddress}`)
}
}, [isAuthenticated, chainId])
Any idea why this isn’t working? Is there a better way to get/set the current users address?